0
votes

I'm running Ruby 2.0.0 and I installed it correctly. Just loaded up a gem 'devise' and as I tried to migrate my database changes, it wouldn't work:

$ rake db:migrate rake aborted! attr_accessible is extracted out of Rails into a gem. Please use new recommended protection model for params(strong_parameters) or add protected_attributes to your Gemfile to use old one.

Then, following another Stackoverflow post, they recommended installing Bundler. I did that successfully and got this:

$ bundle exec rake db:migrate rake aborted! attr_accessible is extracted out of Rails into a gem. Please use new recommended protection model for params(strong_parameters) or add protected_attributes to your Gemfile to use old one.

Is anyone up to the challenge to help?

2
Since it seems like you are new to Rails, if you want to learn with Rails 4 I suggest taking a look at Hartl's Rails Tutorial which now covers Rails 4 and Ruby 2.Althaf Hameez

2 Answers

1
votes

It looks like you are trying to use Rails 4.0.0beta which is not (IMHO) the best choice for a newbie. You’d better switch back to Rails 3* and yield all the advantages of well-documented, tested rock-n-rolling environment. If you still decide to stick to Rails 4… Previously there were no strict rules to deal with mass-assignment. Rails 4 standardises this with Strong Parameters, which has been merged into rails core. Thus, you are to do smth like:

# controllers/my_controller.rb
def create
    @app = MyApp.new(my_params)
  if @app.save
    redirect_to app_path(@app)
  else
    render :new, alert: 'There was a problem'
  end
end

private

def my_params
  params.require(:app).permit(:title, :password)
end

The assignment logic is now being encapsulated in a private method to permit certain values to act as params.

0
votes

Please use Devise 3.0.0.rc, which supports Rails 4.

You will need to:

  • Revert the changes and delete the files generated by older version of Devise.
  • Update Gemfile:

    gem 'devise', '3.0.0.rc'
    
  • Run bundle install.
  • Regenerate Devise initializer and migrations.