我正在关注RyanBates关于使用jCrop裁剪用户头像的屏幕截图http://railscasts.com/episodes/253-carrierwave-file-uploads.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,但它不起作用
您在"attar_accsible"中似乎有两个拼写错误,请尝试attr_accessible
,看看它是否有效。