autogenerate paths in rails 3?

2019-08-20 07:36发布

From the looks of some railscasts (this one in particular), it seems like there is some autogeneration of "*_path" variables that not happening for me. in this rails cast, the edit_mutliple_products_path seems to be generated automagically (i don't normally like using that word). When I follow through the same steps and try to access a similar path, i get this:

undefined local variable or method `edit_multiple_distributions_workflows_path' for #<#<Class:0x132b18a68>:0x132af3290>

2条回答
狗以群分
2楼-- · 2019-08-20 08:14

This is rails 2.X. Rails routes changed in Rails 3. in order to get this route add below to routes.rb:


resources :products do
  collection do
    post 'edit_multiple'
    put  'update_multiple'
  end
end

You will be able to access this paths with

edit_multiple_products_url
edit_multiple_products_path
update_multiple_products_url
update_multiple_products_path

instead of edit_multiple_distributions_workflow_path. Btw where did you get this path from? I did not see it in the railscast.

查看更多
戒情不戒烟
3楼-- · 2019-08-20 08:27

In the given tutorial, which looks like it's from an older Rails, this is the line which would generate the path methods:

map.resources :products, :collection => { :edit_multiple => :post, :update_multiple => :put }

In rails 3, you can see its usage in the docs here: http://guides.rubyonrails.org/routing.html#resource-routing-the-rails-default

查看更多
登录 后发表回答