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 7092413
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T08:18:37+00:00 2026-05-28T08:18:37+00:00

I’m reading a book (Rails 3 in Action) that’s building a project management system

  • 0

I’m reading a book (Rails 3 in Action) that’s building a project management system which has Projects, and then Tickets associated with projects, and users can make Comments on tickets, and when they make a Comment, they can also indicate the State (new, finished etc) of the Ticket.

The users select the state of the Ticket while submitting a Comment form, and this State has to somehow also be reflected on the Ticket.rb model, so after the form is submitted, the author uses a callback

after_create :set_ticket_state

in the Comment class that will also put the state on the Ticket object

My question relates to the code in this callback method. I understand why he write

self.state

with “self” referring to the comment class, but I don’t understand why he uses

self.ticket.state

if he’s trying to update the Ticket object, as “self” would still refer to Comment class.

I’m guessing that he can do it this way because of the association

belongs_to :ticket

but that’s just a guess and I’d like some more explanation if possible.

class Comment < ActiveRecord::Base

after_create :set_ticket_state


belongs_to :ticket
belongs_to :user
belongs_to :state
validates :text, :presence => true
delegate :project, :to => :ticket



private
  def set_ticket_state
      self.ticket.state = self.state
      self.ticket.save!
  end
end
  • 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-28T08:18:38+00:00Added an answer on May 28, 2026 at 8:18 am

    The state that the comment belongs to and the state that the ticket belongs to are two separate objects, or rows in the database. The point of that line of code is to reference the state of the ticket, and update the state it accordingly. If you just use self.state then you will just be changing the state of the comment.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am reading a book about Javascript and jQuery and using one of the
I've got a string that has curly quotes in it. I'd like to replace
We're building an app, our first using Rails 3, and we're having to build
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I used javascript for loading a picture on my website depending on which small

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.