Attr Accessors in Rails 4 Hartl book, Chapter 4.

Hi guys,

I'm following the guide and cruising along quite nicely (I've built 3 other apps so far but this book is teaching me so much I didn't know before!)

I noticed in Chapter 4 (http://ruby.railstutorial.org/chapters/rails-flavored-ruby#sec-a_user_class) There is the following code:

class User
attr_accessor :name, :email

def initialize(attributes = {})
@name = attributes[:name]
@email = attributes[:email]
end

def formatted_email
"#{@name} <#{@email}>"
end
end

Wasn't that deprecated in Rails 4? I am for sure following the 4.0 version of the online textbook. Any clarification would be appreciated.

1 thought on “Attr Accessors in Rails 4 Hartl book, Chapter 4.”

  1. ~~Yes. In rails 4 attr_accessor is deprecated in favor of strong params.~~

    Edit: I’m an idiot.

    It appears attr_accessor is not one of the deprecated things, it’s attr_accessible that’s deprecated in favor of strong params.

    A link to a stackoverflow question explaining the difference between the two, just because I had to go look and find out what the difference was myself. [Difference between attr_accessor and attr_accessible?](http://stackoverflow.com/questions/3136420/difference-between-attr-accessor-and-attr-accessible)

    Reply

Leave a Comment