0

Newbie to rails here, so bear with me.

New app on Rails 4 with ruby 2.0, I installed Devise and followed the instructions(default root, etc). Devise readme on github says it should be compatible with rails4 but

  • db:migrate failed unless I commented out attr_accessible line in User.rb
  • After commenting that out, I get "ActiveModel::ForbiddenAttributesError in Devise::RegistrationsController#create" error in trying to create a user.

I see some stack overflow questions like this, but a lot of the answers jump straight into some complex talk. I get I need to specify permitted attributes for mass assignment, but how? And where? And which attributes need to be permitted, all of them? Only those that I expect to be changed/created at the same time?

Judging by the error would I create a registrations_controller.rb that inherits from Devise::registrationsController ? What do I specify in that?

Any step by step, newbie friendly answers are much appreciated. I've exhausted myself trying different code from answers here and various sites from google searches.

  • What is the error if you dont comment out the attr_accessible – SG 86 Jun 26 '13 at 09:34
  • 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. –  Jun 26 '13 at 09:49

2 Answers2

7

Welcome to stackoverflow!

The problem is that the functinality of attr_accessible changed in rails 4.0

2 possibilities to get it running

1 Update Devise that it can handle Rails 4.0

Add this line to your application's Gemfile:

gem 'devise', '3.0.0.rc' 

And then execute:

$ bundle

2 Add the old functionality of attr_accessible again to rails 4.0

Try to use attr_accessible and dont comment this out.

Add this line to your application's Gemfile:

gem 'protected_attributes'

And then execute:

$ bundle
SG 86
  • 6,974
  • 3
  • 25
  • 34
  • Thanks for this and will try the specific devise version, but I thought devise's master branch has been updated with compatibility for rails 4.0? –  Jun 26 '13 at 10:07
  • just tried 3.0.0.rc and get the same errors asking to use the new "strong parameters". I'd like to learn this, as it seems like new rails functionality. –  Jun 26 '13 at 10:14
  • 1
    If you want to learn how to handle the "Strong parameters" part under devise is helpful https://github.com/plataformatec/devise – SG 86 Jun 26 '13 at 10:26
0

Adding below gems and doing a bundle install worked for me

source 'https://rubygems.org'

gem 'rails', '4.0.2'
gem 'bootstrap-sass', '2.3.2.0'
gem 'devise', '3.0.0.rc' 
gem 'protected_attributes'
gem 'sqlite3'
Prasanth RJ
  • 137
  • 1
  • 8