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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:16:44+00:00 2026-06-14T08:16:44+00:00

So, i have form that updates a record in the database. In my controllers

  • 0

So, i have form that updates a record in the database. In my controllers update action i want to change a value to something if another one of the values is Estimate. Maybe this will make more sense…this is what i’m trying to do.

def update
    @invoice = Invoice.find(params[:id])
    if @invoice.update_attributes(params[:invoice])
        if@invoice.status == "Estimate"
            # if the value of status is Estimate then change the
            # value of estimate_sent_date to the current timestamp
        end
        redirect_to invoices_path
    else
        render 'edit'
    end
end

The only values of the form that i’m concerned with are status and estimate_sent_date. Mostly, i’m just not sure how to change the value of estimate_sent_date and save that record.

Also, should i save everything and then do a separate call to save the estimate_sent_date or just save it all at once? I guess i could change the value of estimate_sent_date before calling if @invoice.update_attributes(params[:invoice]), couldn’t i?

Thanks for the help!

  • 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-06-14T08:16:45+00:00Added an answer on June 14, 2026 at 8:16 am

    As Ryan Bigg says, state machine does work here. An alternative solution is to use a before_save callback on the Invoice model, like so:

    before_save :set_sent_date
    
    def set_sent_date
      if self.status_changed? && self.status == "Estimate"
         self.estimate_sent_date = Time.now
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an html/php form that updates entries on the database server. I need
I've creating one ASP web application, in that application one form have to update
I want to do something like this.. I have a update form in PHP,
I have a form that enables a user to update multiple alert rules records
I have an Ajax form that updates a div when submitted with a submit
I have a form that auto submits and updates the same page. I have
UPDATE 6/21/12 I have a form in rails that is working similar to an
I have a MDI container form, and some child forms that update their title
I have a form that I want to be validated before showing it initially.
I have a question on how to update a particular record in a database

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.