Dynamic Paths in Helper

前端 未结 3 1102
生来不讨喜
生来不讨喜 2021-01-31 17:31

I\'m trying to create a helper method for my admin links. In quite a few views I have the code

<% if current_user %>
<%= link_to \"Edit\", edit_model_pa         


        
3条回答
  •  时光取名叫无心
    2021-01-31 17:54

    Rails provides polymorphic routes to handle this problem: http://api.rubyonrails.org/classes/ActionDispatch/Routing/PolymorphicRoutes.html

    = link_to "Edit", polymorphic_path(model), :method => :put
    

提交回复
热议问题