-1

I defined a new method in my controller to show customized show page for my houses after one click on search results.

houses_controller.rb

 def show_house_search
    @house = House.find(params[:id])
    @photos = @house.photos
  end

then I declared the routes in routes.rb

  get '/show_house_search/:id', to: 'houses#show_house_search', as:'show_house_search'

and when I am using it as

<%= link_to show_house_search_path(house.id),id:'house_search' do %>
<li id="house-<%= house.id %>">
  <span class="user" style="font-size: 15px;font-weight: 200;text-decoration: dotted;"><%= house.title %></span>
  <span class="content"style="font-size: 15px;color: purple;font-weight: 600;">Price <i class="fa fa-inr"></i><%= house.price %></span>
  <span class="badge"><%= house.house_structure%></span>  </span>
  <span class="badge"><%= house.location%></span>  </span>
</li>
  <%end%>

clicking on this link is showing me this error:

Routing Error
No route matches [GET] "/show_house_search.38"

while I also searched for a route for my request using rails routes

    show_house_search_path  GET     /show_house_search/:id(.:format) houses#show_house_search
Eyeslandic
  • 12,640
  • 12
  • 34
  • 47
Nischay Namdev
  • 485
  • 5
  • 20

2 Answers2

1

Please change menthod

show_house_search_path(house.id) 

to

show_house_search_path(id: house.id). 

As shown in routes.rb, path is /show_house_search/:id(.:format), it seems that id is considered as :format hence appending to routes as( .id).

Eyeslandic
  • 12,640
  • 12
  • 34
  • 47
Sanjiv
  • 653
  • 4
  • 12
  • This is not needed, as the op commented but for some reason deleted. He had forgotten to restart the server. – Eyeslandic Apr 25 '17 at 10:28
1

try below code:

<%= link_to show_house_search_path(id: house.id) ,id:'house_search' do %>
puneet18
  • 4,537
  • 2
  • 18
  • 25
  • This is not needed, as the op commented but for some reason deleted. He had forgotten to restart the server. – Eyeslandic Apr 25 '17 at 10:28