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 ( There is the following code:

class User
attr_accessor :name, :email

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

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

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?](


Leave a Comment