0

jCrop http://railscasts.com/episodes/253-carrierwave-file-uploadsを使用して User Avatar をトリミングすることに関するこの RyanBates のスクリーンキャストに従っています。Ryan は認証システムをゼロから使用していますが、私はこの目的のためにDeviseを使用しています。

クロッピングが処理されるcrop.html.hamlにユーザーを連れて行くために、app/controllersでこのファイルを作成し、指定することで、 Deviseのregistration_controller.rbを上書きしました

routes.rb

devise_for  :users, path_names: { sign_in: "login", sign_out: "logout" }, 
          controllers: { registrations: "registrations" }

registration_controller.rbの更新アクションは次のようになります

def update
if resource.update_with_password(resource_params)
    if params[:user][:avatar].present?
    render 'crop'
  else
    expire_session_data_after_sign_in!
    redirect_to users_path, notice: "User updated."
  end
 else
    clean_up_passwords(resource)
    flash[:notice] = flash[:notice].to_a.concat resource.errors.full_messages
    session[:subscription] = resource
  redirect_to root_path
 end

終わり

「クロップ」をクリックすると、次のエラーが発生します。

ActiveModel::MassAssignmentSecurity::Error in UsersController#update

Can't mass-assign protected attributes: crop_x, crop_y, crop_w, crop_h

user.rb

attr_accessor :crop_x, :crop_y, :crop_w, :crop_h

attar_accessible にも入れてみましたがうまくいきません

4

1 に答える 1

1

「attar_accessible」に 2 つのタイプミスがあるようですattr_accessible。動作するかどうか試してみてください。

于 2012-11-25T02:32:03.640 に答える