我通过与用户,附件和表单模型建立关联来拥有has_many,我只想删除关联,而不能删除附件。我写了名为“ sil”的删除方法
user.rb
has_many :forms
has_many :attachments, through: :forms
Attachment.rb
has_many :forms
has_many :users, through: :forms
form.rb
belongs_to :user
belongs_to :attachment
硅法
def sil # remove the product from user
@user = User.find(params[:id])
attachment = Attachment.find(params[:attachid])
@user.attachments.delete(attachment)
redirect_to user_path(@user.id)
end
看法
<%= button_to "Sil",attach ,method: "delete",:controller => "attachments", :action => "sil" , :attachid =>attach.id %>
我具有用于附件的资源路由,并且具有用于附件的delete方法以删除元素。我需要帮助以查看Sil方法的路线和路线
尝试这个:
resources :attachments do
member do
delete 'sil'
end
end
路由助手是这样的:
sil_attachment_path(id: attachmentid, user_id: userid)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句