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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T16:01:45+00:00 2026-05-13T16:01:45+00:00

First, I’ve generated scaffold called ‘item’ I’d like to check which fields of the

  • 0

First, I’ve generated scaffold called ‘item’

I’d like to check which fields of the item are modified. and I’ve tried two possible attempts, those’re not work tho.

First Attempt!

def edit
  @item = Item.find(params[:id])
  @item_before_update = @item.dup
end

def update
  @item = Item.find(params[:id])
  # compare @item_before_update and @item here, but @item_before_update is NIL !!!
end

Second Attempt!
I looked for the way passing data from view to controller and I couldn’t.
edit.html.erb

<% @item_before_update = @item.dup %> # I thought @item_before_update can be read in update method of item controller. But NO.
<% params[:item_before_update] = @item.dup %> # And I also thought params[:item_before_update] can be read in update mothod of item controller. But AGAIN NO

<% form_for(@item) do |f| %>
# omitted
<% end %>

Please let me know how to solve this problem 🙁

  • 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-13T16:01:45+00:00Added an answer on May 13, 2026 at 4:01 pm

    Attributes that have changes that have not been persisted will respond true to changed?

    @item.title_changed? #=> true
    

    You can get an array of changed attributes by using changed

    @item.changed #=> ['title'] 
    

    For your #update action, you need to use attributes= to change the object, then you can use changed and changed? before persisting:

    def update
      @item = Item.find(params[:id])
      @item.attributes = params[:item]
      @item.changed #=> ['title']
      ... do stuff
      @item.save
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First of all, many thanks to Craig for the excellent answer below which I
First time poster, be gentle ;-) I'm writing an audio app (in C++) which
First, here is what I would like to do: Row 1 Row 2 Row
First of all, my table structure is something similar like this: CREATE TABLE Testing(
First of all, i would like to explain my condition right now. I'm using
First, a little background. I have two ASP.NET web applications that use SQLServer session
First some context: I have an MVC3 .net project which, for the sake of
First, let's get the security considerations out of the way. I'm using simple authentication
First off, I am using Windows XP. I have multiple hard drives and it
First off, I understand the reasons why an interface or abstract class (in the

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.