2

I'm trying to use meta_search for global search and models search.

for models search, in index file of the model. i create a form_for with this code.

<%= form_for @search, :url => building_path, :html => {:method => :get} do |f| %>
<%= f.label :name %>
<%= f.text_field :city %>
<%= f.submit %>
<% end %>

my model controller have this code

def index
@search = Building.search(params[:search])
@buildings = @search.all
end 

But, when i try to show the index for my building, i have this error message

ActionController::RoutingError in Buildings#index

Showing /Users/stephanebaribeau/Sites/cadifice/app/views/buildings/index.html.erb where line #4 raised:

No route matches {:action=>"show", :controller=>"buildings"}

Extracted source (around line #4):

1: <h1>Listing buildings</h1>
2:  
3: 
4: <%= form_for @search, :url => building_path, :html => {:method => :get} do |f| %>
5:   <%= f.label :name %>
6:   <%= f.text_field :city %>
7:   <%= f.submit %>

my routes.rb have this resources :buildings do resources :floors end

i tried without plurial, same error.

my rake routes give me that

       building_floors GET    /buildings/:building_id/floors(.:format)            {:controller=>"floors", :action=>"index"}
                       POST   /buildings/:building_id/floors(.:format)            {:controller=>"floors", :action=>"create"}
    new_building_floor GET    /buildings/:building_id/floors/new(.:format)        {:controller=>"floors", :action=>"new"}
   edit_building_floor GET    /buildings/:building_id/floors/:id/edit(.:format)   {:controller=>"floors", :action=>"edit"}
        building_floor GET    /buildings/:building_id/floors/:id(.:format)        {:controller=>"floors", :action=>"show"}
                       PUT    /buildings/:building_id/floors/:id(.:format)        {:controller=>"floors", :action=>"update"}
                       DELETE /buildings/:building_id/floors/:id(.:format)        {:controller=>"floors", :action=>"destroy"}
             buildings GET    /buildings(.:format)                                {:controller=>"buildings", :action=>"index"}
                       POST   /buildings(.:format)                                {:controller=>"buildings", :action=>"create"}
          new_building GET    /buildings/new(.:format)                            {:controller=>"buildings", :action=>"new"}
         edit_building GET    /buildings/:id/edit(.:format)                       {:controller=>"buildings", :action=>"edit"}
              building GET    /buildings/:id(.:format)                            {:controller=>"buildings", :action=>"show"}
                       PUT    /buildings/:id(.:format)                            {:controller=>"buildings", :action=>"update"}
                       DELETE /buildings/:id(.:format)                            {:controller=>"buildings", :action=>"destroy"}

whats wrong with my routes? thanks

2 Answers 2

2

Change the url to buildings_path instead of building_path like this:

 <%= form_for @search, :url => buildings_path, :html => {:method => :get} do |f| %>
0
1

You are using building_path in your form_for line, which will take you to the buildings/:id i.e. show page. You should use buildings_path, which takes you to the index page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.