Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby Build a Simple Ruby on Rails Application Creating an Authentication System Generating the Devise Views

Marc Murray
Marc Murray
4,618 Points

Error from tutorial missing, different error arises afterwards.

Hi guys, sorry to be asking so many questions but this course is giving me a bit of a hard time!
I have generated the necessary views, and made the changes to the new registration page. I added the containers for first name, last name, and profile name.

Then, when I start the server back up and try to add a new user, there is no error whatsoever. The "ActiveModel::MassAssignmentSecurity" message doesn't appear, and the user is signed up. I am of course a little suspicious that something seemed to work that didn't in the tutorial. Has Rails/Devise updated to handle this process automatically?

Also, I don't know how to check the database to make sure the user has in fact BEEN signed up, so I am a little worried I just get the confirmation message and that's it.

When I enter the user.rb file, there is no "#Setup accessible attributes for your model" section at all, and when I copy that line in I am met with the following error:

"Undefined method ''attr_accessible for #<class:0x007fe8aee3c300>"

 

So I guess I'm looking for a little clarification as to what has gone wrong, as well as some help with making sure I am okay to move on to the next stage of this course.

 

Thanks in advance to anyone willing to lend a hand. :)

2 Answers

I did it with Rails 4. I found this solution to work well:

add file registrations_controller.rb with

class RegistrationsController < Devise::RegistrationsController

private

def sign_up_params params.require(:user).permit(:first_name, :last_name, :email, :password, :password_confirmation) end

def account_update_params params.require(:user).permit(:first_name, :last_name, :email, :password, :password_confirmation, :current_password) end end

Update routes.rb with

devise_for :users, :controllers => { registrations: 'registrations' }

http://jacopretorius.net/2014/03/adding-custom-fields-to-your-devise-user-model-in-rails-4.html

Without knowing the details of your setup, it's hard to accurately answer your questions, but I believe you have most likely installed Rails 4 rather than Rails 3. In Rails 4 they have changed how they manage the error you are seeing. Instead of setting up attr_accessible in the model you need to setup permitted parameters in the controller.

Devise will automatically handle this for any of their standard fields, but you do need to set them for fields you create on the User model.

You have two options, one is to switch to a Rails 3 environment for the course or two research the necessary changes to make the code work with Rails 4. You can check your Rails version from the command line with "rails -v".

To see what's in the DB you can install a program like SQLite Browser to see the records or you can go into the rails console on the command line ("rails console") and then "User.all" to get all of the User data you've saved.