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 %>
また、「削除してもよろしいですか?」という確認メッセージはどのようにすればよいですか?リンクに追加できますか?
どんなアドバイスでも大歓迎です!