ruby-on-rails - Rails 3 的路由问题

标签 ruby-on-rails ruby ruby-on-rails-3

我正在尝试使用meta_search进行全局搜索和模型搜索。

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

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

我的模型 Controller 有这个代码

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有这个 资源:建筑物 资源:楼层 结束

我尝试了没有复数,同样的错误。

我的 rake 路线给了我这个

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

我的路线有什么问题吗? 谢谢

最佳答案

将网址更改为 buildings_path 而不是 building_path,如下所示:

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

关于ruby-on-rails - Rails 3 的路由问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7111424/

相关文章:

html - 访问 Rails 后端的 Javascript 变量

ruby-on-rails - Heroku Drop Table Rails 帮助

database - 回形针不保存附件

ruby-on-rails - Rails 3 项目的基于 I18n 浏览器的编辑器(运行本地非 saas 项目)?

ruby-on-rails - Ruby on Rails 按 id(和版本?)排序

ruby-on-rails - Ruby on Rails - 计算数字范围的大小

mysql - 从 has_one 关联中调用一个值

arrays - Ruby - 数组交集(有重复项)

ruby-on-rails - wordpress 和 Ruby on rails

ruby-on-rails - Rails - update_column 和 ActiveRecord 枚举