[英]Rails link_to helper
I have following route in my rails application: 我的rails应用程序中有以下路由:
recipient_template DELETE /templates/:id/recipient/:recipient_type/:recipient_id(.:format)
How can I create a link in my view to this specific route given that both recipient type and recipient id are dynamically filled by my application. 如果我的应用程序动态填充收件人类型和收件人ID,我如何在视图中为此特定路径创建链接。
Edit
编辑
Here is my model and route.rb file 这是我的模型和route.rb文件
class Template < ActiveRecord::Base
has_and_belongs_to_many :individuals
has_and_belongs_to_many :groups
def recipients
{:groups => self.groups, :individuals => self.individuals}
end
end
resources :templates do
member do
match 'recipient/:recipient_type/:recipient_id', :to => :recipient_remove, :via => :delete
end
end
Try this 尝试这个
pass recipient_type and recipient_id values in path along with template id 传递路径中的recipient_type和recipient_id值以及模板ID
link_to "Delete Recipient", recipient_remove_path(template.id, recipient_type, recipient_id), method: :delete
In your routes 在你的路线
match 'recipient/:recipient_type/:recipient_id' => "controller#action", :as => :recipient_remove, :via => :delete
and you should pass recipient class name in recipient type and id of recipients in reciepient_id 并且您应该在reciepient_id中的收件人类型和收件人ID中传递收件人类名
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.