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

  • Home
  • SEARCH
  • 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 7602615
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:27:25+00:00 2026-05-30T23:27:25+00:00

I have a Printer model to which I added a master boolean column. A

  • 0

I have a Printer model to which I added a master boolean column. A printer belongs_to :restaurant. The master flag indicated whether this printer is the primary printer of this restaurant.

I have a method in the Printer model:

def set_master_on_create
  if self.restaurant.printers.empty?
    self[:master] = true
  else
    self[:master] = false
  end
end

and set this callback: before_create :set_master_on_create

If I run this method as a before_create then creating a new printer will fail. If I change the callback to after_validation creating the new object will work flawlessly, even with the :on => :create option.

Does Rails freeze the object so i can no longer change values after a certain point which will cause the Rollback I get? Any help appreciated.

I am on Rails 3.2.2 and sqlite in dev mode.

  • 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-30T23:27:27+00:00Added an answer on May 30, 2026 at 11:27 pm

    i think the problem is that a before_create method returning false will prevent your object from being saved. try adding a return true

    and i guess you set the master attribute like this: self.master = true

    def set_master_on_create
      if self.restaurant.printers.empty?
        self.master = true
      else
        self.master = false
      end
    
      return true
    end
    

    If a before_* callback cancels the action a ROLLBACK is issued. You
    can also trigger a ROLLBACK raising an exception in any of the
    callbacks, including after_* hooks. Note, however, that in that case
    the client needs to be aware of it because an ordinary save will raise
    such exception instead of quietly returning false.
    http://api.rubyonrails.org/classes/ActiveRecord/Callbacks.html

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

Sidebar

Related Questions

I have a QListView from which I obtain a QAbstractItemModel with list->model(); After this,
Many databases have a hidden primary key column. MySQL implements this as _rowid. In
I have a webpage that activates a print job on a printer. This works
Using MVC2 I have an AJAX form which is posting to a bound model.
I have a user model and an operator model which belongs to user. I
I have an HP Laserjet 2420 PCL6 printer on my network for which drivers
I have a model with a json field. The contents of which may or
If I have a printer hooked directly to a pc (a kiosk with a
I have implemented a printer delivery extension based on MS example in SSRS 2005.
I am using a dot matrix printer and have to do a continious printing

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.