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

Simon White
Simon White
2,491 Points

Missing field data?

I'm a bit confused by this lesson....

Firstly, I don't receive any error message regarding protected attributes and when I insert the required attr_accessible line into the model I get a rails based error suggesting I shouldn't be setting accessible attributes that way anymore.

Also, I noticed that when browsing the database with the rails console the first_name, last_name and profile_name fields are blank (i.e. not recording data from the forms). Thought this may have something to do with the above, but then I noticed the teachers output in the console was also not recording any data for these fields.

Am I missing something?

Simon White
Simon White
2,491 Points

This was the exact error. Presuming this could be to do with the fact I'm using Rails 4 (I'm very new to RoR).

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.

1 Answer

Justin Horner
STAFF
Justin Horner
Treehouse Guest Teacher

Hello Simon,

Rails 4 introduced strong parameters which changes the way this is done. Now you will set the attributes that are permitted from the controller instead of the model.

Here's an example from the documentation.

 private
    # Using a private method to encapsulate the permissible parameters is
    # just a good pattern since you'll be able to reuse the same permit
    # list between create and update. Also, you can specialize this method
    # with per-user checking of permissible attributes.
    def person_params
      params.require(:person).permit(:name, :age)
    end

Since this course is quite old, you might want to consider going through Build a Todo List Application with Rails 4 if you haven't already. You'll probably encounter several difficulties while going through Build a Simple Ruby on Rails Application with a recent version of Rails.

Not impossible, of course, just not optimal if you're trying to learn Rails for the first time :)

I hope this helps.

Simon White
Simon White
2,491 Points

Thanks Justin,

I'll give the to-do list a try.

Simon