autogenerate paths in rails 3?

你。 提交于 2019-12-25 02:21:15

问题


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>

回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/8550203/autogenerate-paths-in-rails-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!