Search code examples
ruby-on-railsruby-on-rails-3devisejcrop

Can't mass-assign protected elements: crop_x, crop_y, crop_w, crop_h. Devise and jCrop. Ruby on Rails


I am following this RyanBates's screencast on cropping User Avatar using jCrop http://railscasts.com/episodes/253-carrierwave-file-uploads. Ryan's using authentication system from scratch, but I use Devise for this purposes.

In order to bring user to crop.html.haml where the cropping is handled I overwrited Devise's registration_controller.rb by creating this file in app/controllers and specifying

routes.rb

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

My update action in registration_controller.rb looks like this below

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

end

When I click "crop" that lead to the following error:

ActiveModel::MassAssignmentSecurity::Error in UsersController#update

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

In user.rb I have

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

I also tried to put it into attar_accesible, but it doesn't work


Solution

  • You seem to have two typos in "attar_accesible", try attr_accessible and see if it works.