在rails 3.2.13中,我有以下多对多关系设置
帐户模型:
has_many :memberships
has_many :users, :through => :memberships, :dependent => :destroy
用户模型:
has_many :memberships
has_many :accounts, :through => :memberships, :dependent => :destroy
会员模式:
belongs_to :account
belongs_to :user
在routes.rb中我有:
scope ":account_id" do
resources :users
end
rake routes命令给出了以下内容:
users GET /:account_id/users(.:format) users#index
POST /:account_id/users(.:format) users#create
new_user GET /:account_id/users/new(.:format) users#new
edit_user GET /:account_id/users/:id/edit(.:format) users#edit
user GET /:account_id/users/:id(.:format) users#show
PUT /:account_id/users/:id(.:format) users#update
DELETE /:account_id/users/:id(.:format) users#destroy
问题:我能够成功生成除“销毁/删除”之外的所有链接。
“编辑”链接的设置如下:
<%= link_to "Edit", :controller => "users", :action=>"edit" , :account_id=>@account.id , :id =>membership.user.id%>
我试图像这样设置“删除”链接,但它不起作用 - 它转而采用“显示”操作(生成的链接为http://www.example.com/20/users/13?method=delete):
<%= link_to 'Destroy', :controller=>"users", :action=>"destroy", :method=>'delete', :account_id => @account.id, :id=>membership.user.id %>
此外,如何确认消息“您确定要删除吗?”可以添加到链接?
非常感谢任何建议!
答案 0 :(得分:0)
可以通过在链接中设置“data-confirm”属性来添加确认消息,如下所示:
<%= link_to 'Destroy', :controller=>"users", :action=>"destroy", :method=>'delete', :account_id => @account.id, :id=>membership.user.id, "data-confirm"=>"Are you sure you want to delete?" %>