【发布时间】:2014-05-02 01:53:23
【问题描述】:
我的 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
【问题讨论】:
-
你试过运行
rake routes吗?它应该给出答案! -
link_to('Template', recipient_template_path(recipient_type: recipient_type,recipient_type: recipient_type ))可能工作... -
@xlembouras 我上面提供的是表单 rake 路由。我在这里想要实现的是从模型模板中删除特定的收件人。收件人可以是团体或个人,因此我必须指定所选收件人的类型和 ID。
-
@ArupRakshit 我试过了,结果是:Started DELETE "/templates/1/recipient?recipient_id=id&recipient_type=type"
-
@ArupRakshit 那行不通。还有你为什么要通过
recipient_type两次。
标签: ruby-on-rails ruby