我的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
答案 0 :(得分:2)
试试这个
在路径中传递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中传递收件人类名