我正在关注 RyanBates 关于使用jCrop http://railscasts.com/episodes/253-carrierwave-file-uploads裁剪用户头像的截屏视频。Ryan 从头开始使用身份验证系统,但我为此使用了Devise 。
为了将用户带到处理裁剪的crop.html.haml,我通过在app/ controllers中创建此文件并指定
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_accesible,但它不起作用