在 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=删除):
<%= link_to 'Destroy', :controller=>"users", :action=>"destroy", :method=>'delete', :account_id => @account.id, :id=>membership.user.id %>
另外,如何确认消息“您确定要删除吗?” 可以加链接吗?
任何建议都非常感谢!