簡體   English   中英

Rails link_to helper

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM