2011-08-18 189 views
2

我试图使用meta_search全局搜索和模型搜索。路由问题的Rails 3

用于模型搜索,位于模型的索引文件中。我用这段代码创建一个form_for。

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

我的模型控制器有这样的代码

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

但是,当我试图表明该指数为我建设,我有这个错误信息

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 %> 

我的routes.rb有这 资源:建筑做 资源:地板 结束

我尝试过没有多少,同样的错误。

我耙路线给我

 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"} 

什么错我的路线? 感谢

回答

2

URL更改为buildings_path,而不是building_path这样的:

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

我试过太多,同样的路线错误。 – neimad

1

您正在使用building_path的form_for线,这将带你到建筑/:ID即显示页面。您应该使用buildings_path,这需要你到指数页。