尝试在其父视图中为nested_attributes对象创建删除link_to

时间:2012-03-29 13:44:10

标签: ruby-on-rails ruby-on-rails-3 ruby-on-rails-3.1 nested-attributes

所以我遇到的情况是用户都是帐户所有。

我列出了每个帐户的用户,如下所示:

for @user in @account.users.where(['email <> ?', 'null']).sort! {|b, a| a.id <=> b.id}

对于每个用户,我希望能够通过链接提供删除功能。我有以下内容:

<p>Are you sure you want to delete <%=h @user.firstname %>?:
<%= link_to "Yes", account_users_path(@user), :remote => true, :method => :delete, :class => "button" %>
<span class="button canceldeleteobject"> No </span></p>

然而,当我跑步时,我得到:

Started DELETE "/accounts/28/users" for ::1 at 2012-03-29 09:42:39 -0400

AbstractController::ActionNotFound (The action '28' could not be found for AccountsController):

用户ID是'28',其中帐号id是'15',因此我感觉它与account_users_path元素有关,但是你可以做的任何关于这种类型的nested_attribute删除的最佳方法非常感谢。

编辑:

路线看起来像这样:

  devise_for :users, :controllers => { :sessions => "sessions" }, :skip => :registrations do
    get 'users/edit' => 'registrations#edit', :as => 'edit_user_registration'
    put 'users' => 'registrations#update', :as => 'user_registration'
    delete 'users' => 'registrations#destroy', :as => 'destroy_user_registration'    
  end

  resources :accounts do
    resources :assessments, :areas, :risks, :controls, :persons, :roles, :mitigations, :comments, :users
    collection do
      put :update_attribute_on_the_spot
      get :get_attribute_on_the_spot
    end
  end

1 个答案:

答案 0 :(得分:0)

您应该使用account_user_path(@account, @user)代替(您已复数users,并且未包含父account)。