[英]Rails link_to helper
我的rails应用程序中有以下路由:
recipient_template DELETE /templates/:id/recipient/:recipient_type/:recipient_id(.:format)
如果我的应用程序动态填充收件人类型和收件人ID,我如何在视图中为此特定路径创建链接。
编辑
这是我的模型和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
尝试这个
传递路径中的recipient_type和recipient_id值以及模板ID
link_to "Delete Recipient", recipient_remove_path(template.id, recipient_type, recipient_id), method: :delete
在你的路线
match 'recipient/:recipient_type/:recipient_id' => "controller#action", :as => :recipient_remove, :via => :delete
并且您应该在reciepient_id中的收件人类型和收件人ID中传递收件人类名
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.