2

ルーティングは、常に私にとって厄介なことの 1 つでした。Rake ルートには、使用できる情報が表示されますが、その情報を思い通りに操作することはできません。私のプログラムには、devise を使用したユーザー モデルがあります。各ユーザーは従業員を作成でき、従業員は (ログイン資格情報などを使用して) 自分のユーザーになります。

従業員の「更新」メソッドに問題があります。ユーザー更新メソッドは正常に機能します。rake routes を実行すると、次の行が表示されます

PUT    /users(.:format)                  devise/registrations#update
PUT    /employees/:id(.:format)          employees#update

従業員を更新しようとすると、エラーが発生します

No route matches [PUT] "/employees"

それが私が PUT できるようにしたいルートですが、レールは私に /employees/:id を提供するように見えます。

私のルートファイルには含まれています

devise_for :users
resources :users, :only => [:index, :show, :new, :edit, :create, :update, :destroy]
resources :employees, :only => [:index, :show, :new, :edit, :create, :update, :destroy]

どんな助けでも素晴らしいでしょう、そして私のルートを操作することに関する追加情報は素晴らしいでしょう. ありがとう!

編集

これが私の更新従業員コントローラーメソッドです

  def update
    @employee = current_company.users.find(params[:id])
    if @employee.update_attributes(params[:employee])
      redirect_to :action => 'show', :id => @employee.id
      flash[:notice] = "Employee information updated"
    else
      render :action => 'edit'
      flash[:notice] = "No edits were made"
    end
  end
4

1 に答える 1