Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6686805
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:12:51+00:00 2026-05-26T05:12:51+00:00

newbie alert I’m watching one of Ryan Bate’s RailsCasts on virtual attributes. He’s adding

  • 0

newbie alert

I’m watching one of Ryan Bate’s RailsCasts on virtual attributes. He’s adding tags to an article on a blogging platform. http://media.railscasts.com/assets/episodes/videos/167-more-on-virtual-attributes.mp4

At one point he has working code

attr_accessor :tag_names

In this example, the tag names do not appear in the form if they validate, so he changes the name of the attribute, and adds a method so that the tag names persist if there’s a validation error on a different field

attr_writer :tag_names



def tag_names
    @tag_names || tags.map(&:name).join(' ')
end

My question is, can you please explain the significance of changing it from attr_accessor to attr_writer in combination with the method he added? Why did he need to change the attribute name when he added that method?

(note, i have read documentation about attr_accessor and attr_writer, but it’s still not clicking enough so I’m not getting why he’s making this change when he creates that method)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T05:12:52+00:00Added an answer on May 26, 2026 at 5:12 am

    attr_accessor: :tag_names creates these two methods:

    def tag_names
      @tag_names 
    end
    

    and

    def tag_names=(value)
      @tag_names=value
    end
    

    Because Ryan has his own tag_names (“reader”) method he doesn’t need to dynamically create it with attr_accessor. He needs only the (“writer”) method which is created by attr_writer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am a jquery newbie and have been adding alert timestamps into my html
Newbie Alert: I'm new to Python and when I'm basically adding values to a
NEWBIE ALERT! Here's the situation. I've got an Android ListActivity class (AppWindow) that contains
[Android Newbie alert] I need to capture the contents of a WebView in a
(Newbie DBUnit question Alert!) It appears that DBUnit for each table 'deletes all the
Newbie Alert: while working on my android application my program was acting kind of
Newbie alert! OK, I have a working central Mercurial repository that I've been working
NEWBIE ALERT! background: For the first time, I am writing a model that needs
(newbie alert) I need to program a multiparty communication service for a course project,
.NET newbie alert Using Visual C# 2008 Express Edition I have accidentally created a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.