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

The Archive Base Latest Questions

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

The attributes method returns a hash of all the attributes with their names as

  • 0

The attributes method returns a hash of all the attributes with their names as keys and the values of the attributes as values; I want to utilize this method, creating a new derivative of the update_attributes(attributes) method, lets call it jz_attributes(attributes).

Update_attributes does this:

def update_attributes(attributes)
   self.attributes = attributes
       save
   end

And jz_attributes(attributes) will do something slightly different:

def jz_attributes(attributes)
    debugger
    self.attributes = attributes
       #does something else
end

I want to fully utilize ActiveRecords attributes method, but I’m running into trouble:

def attributes
         self.attribute_names.inject({}) do |attrs, name|
           attrs[name] = read_attribute(name)
           attrs
        end
end

Here is what terminal is saying:

   28   end
   29  end
   30  
   31  def jz_attributes(attributes)
   32   debugger
=> 33   self.attributes = attributes
   34  end
   35  
   36  
   37   #inventory_to_increment.quantity = quantity.to_i
(rdb:1) p attributes
nil
(rdb:1) next
/Users/justinz/.gem/ruby/1.8/gems/actionpack-2.3.5/lib/action_controller/rescue.rb:162
rescue_action(exception)

My controller that utilizes jz_attributes:

def cart2_update
        @cart = find_cart
        @cart.jz_attributes(params[:cart_item])
end

Do you see anything obvious that I am doing wrong? Thanks!

  • 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-13T13:53:45+00:00Added an answer on May 13, 2026 at 1:53 pm

    I recently did some very similar things when building an order form system. The order form system had to keep updating the form with changes dynamically, but I did not want to save it to the database until the user had confirmed everything. (Such as taxes, etc).

    I think your on the right track, but from what you have pasted here it looks like you are trying to set nil to attributes? Maybe you can post what the params are for the request en entirety?

    Assuming you are doing something similar, why not just pass attributes= ? It will not save the model, only update_attributes= should save it at this point. If you need to do something else surrounding attributes= that you want to accomplish with jz_attributes, maybe you can manipulate the parameters before they get to there, or accomplish this goal through some other means?

    def cart2_update
            @cart = find_cart
            @cart.attributes=(params[:cart_item])
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've written a method to turn a hash (nested if necessary) of values into
I want to fetch only changed attributes of an object. Is there any method
I have a couple of method attributes which do some logging. Our logging code
Using Ruby (1.8.7) and Rails (2.3.8) doing myObject.attributes gives you a hash of attribute
If a static method returns an object .. can I in one line get
I want to realize this class into php extension: class MyClass { protected $attrs
In Fluent NHibernate, References() returns an object which doesn't support the 'ReadOnly()' method. I'm
I'm struggling to define a class method that populates and returns a collection of
The jQuery documentation states that As of jQuery 1.6, the .attr() method returns undefined
I have trouble deserializing the result from my WCF webservice. The method returns 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.