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 Updating the User Model

Brandon Hay
Brandon Hay
1,109 Points

I'm using a version of Devise/ RoR that doesn't have this attr_accessible code in the file. Is it not necessary anymore?

I added it in manually and got an error that attr_accessible wasn't recognized when starting up the rails server and checking the page.

10 Answers

Brandon Barrette
Brandon Barrette
20,485 Points

Technically it is supported in a gem (rails/protected_attributes). It was removed because of security reasons in Rails 4. Instead, Rails 4 uses strong parameters. There are some good fixes here on the forum if you attempt to do the Treebook application:

https://teamtreehouse.com/forum/attraccessible-missing-in-rails-4-heres-the-workaround-for-the-treebook-tutorial

I highly recommend you do the ODOT projects first, as they follow Rails 4, then try out the Treebook videos.

John Steer-Fowler
PLUS
John Steer-Fowler
Courses Plus Student 11,734 Points

Hey Brandon,

attr_accessible is no longer supported as of Rails 4

Hope that helps answer your question :D

Keep up the good work

Kang-Kyu Lee
Kang-Kyu Lee
52,045 Points

Devise gem documentation "Rails 4 moved the parameter sanitization from the model to the controller, causing Devise to handle this concern at the controller as well." maybe do you look for something like this.

https://github.com/plataformatec/devise#strong-parameters

Brandon Hay
Brandon Hay
1,109 Points

Thank you, my friends!

Brandon Hay
Brandon Hay
1,109 Points

Follow up question: Would it be alright to just skip those attr_accessible steps and not perform any workaround since it's already "built" in to RoR v4? Or would that prevent me from adding new fields to the database?

Kang-Kyu Lee
Kang-Kyu Lee
52,045 Points

I think you may simply download project file of the course and bundle install Rails 3.2 and follow along. Or start fresh with rails 4 Odot project

Also, it's good to check this Railscasts episode -- http://railscasts.com/episodes/371-strong-parameters

Brandon Hay
Brandon Hay
1,109 Points

So in the tutorial that you guys provide it says to put this code into a new controller file:

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

I know that that is only part of it but I get this syntax error when trying to load the page

/Users/bhay/Code/Treebook/Treebook/app/controllers/registrations_controller.rb:5: syntax error, unexpected '.', expecting ';' or '\n' def sign_up_params params.require(:user).permit(:first_... ^

I'm 99% confident I named the file correctly, named the new user tables correctly etc.

I'm using rails v 4.1.5 and ruby 2.1.2p95

John Steer-Fowler
John Steer-Fowler
Courses Plus Student 11,734 Points

I did the ruby Markdown for you. Look at the Markdown Cheatsheet for help

Brandon Hay
Brandon Hay
1,109 Points

Ehhh, so I think I figured it out. I put def sign_up_params on its own line and then made a line break for the rest. D'oh! I guess I just don't know enough about Ruby that line breaks matter?

Thanks for responses!

John Steer-Fowler
John Steer-Fowler
Courses Plus Student 11,734 Points

Hey Brandon,

Have you looked at the Ruby language before starting to learn Rails? It's not 100% necessary, but I personally recommend it. It really helps you understand Rails more.

Brandon Hay
Brandon Hay
1,109 Points

John,

I have not, and I totally should. :)

John Steer-Fowler
John Steer-Fowler
Courses Plus Student 11,734 Points

I did exactly what you did. I went straight into learning Ruby on Rails without looking much at the Ruby language before hand. I worked my way through all the tutorials, but found that it felt like it wasn't sinking in because I didn't understand exactly what was going on. I see it like this:

In math, someone can show you an algebraic equation and they can show you the answer. You can learn that equation off-by-heart and repeat it anywhere and everywhere. But if someone gives you a different equation with no answer, are you going to be able to answer it? No. because you don't actually understand the science behind it. Once you learn the science behind equations, you can solve most equations without having to learn them.

This is how I see learning Ruby on Rails. Rails is the equation. You can learn it from a tutorial and copy it, but you can never actually reproduce it for your own project or for a non-Treehouse project until you learn why and how things happen. Learning Ruby before doing Rails is like learning the science behind equations.

I hope this helps you understand.

Brandon Hay
Brandon Hay
1,109 Points

Thanks. My goal is to have complete understanding, so I will check out the treehouse Ruby track.

John Steer-Fowler
John Steer-Fowler
Courses Plus Student 11,734 Points

No problem. I would advise going beyond the Treehouse Ruby course. It's made to give you a fairly basic knowledge of the language. I advise reading a Ruby book if you really want to get a deep understanding.

Your next question will probably be: "Which book do you recommend?" so I will answer that too. The book I read and personally recommend is Beginning Ruby, it's a really detailed and long book, but reading the first few chapters will give you more understanding than from the Treehouse Ruby course.

You can find the book pdf free here: [Beginning Ruby]http://peterhurford.com/tilde/files/beginningruby.pdf)