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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T06:39:23+00:00 2026-05-18T06:39:23+00:00

I’m a newbie to rails development. I have a custom method placed in my

  • 0

I’m a newbie to rails development.
I have a custom method placed in my Post class, in which I want to update a particular attribute/variable of that Post class. My method goes as below:-

def update_bid_winner (winner_id)
  @bid_winner_id = winner_id
  puts @bid_winner_id
  save
  puts "post saved"
end

But when I display the Post object , the bid_winner_id variable is still not updated.
I doubt that the object’s save is not successful after the updation, because
the puts placed the above method prints the correct value with which I’m trying to update.

Logs from my rails server window:-

2      <<< Output of the puts placed for debugging
post saved


Started GET "/posts/1/bids/1/offer_bid" for 127.0.0.1 at Sun Nov 21 13:21:59 +0530 2010
Processing by BidsController#offer_bid as HTML
Parameters: {"post_id"=>"1", "id"=>"1"}
User Load (3.1ms)  SELECT "users".* FROM "users" WHERE ("users"."id" = 1) LIMIT 1
Post Load (3.1ms)  SELECT "posts".* FROM "posts" WHERE ("posts"."id" = 1) LIMIT 1
Bid Load (0.5ms)  SELECT "bids".* FROM "bids" WHERE ("bids"."id" = 1) LIMIT 1
Redirected to http://localhost:3000/posts/1
Completed 302 Found in 167ms

My post schema as follows:-

create_table "posts", :force => true do |t|
t.integer  "user_id"
t.string   "title"
t.text     "body"
t.integer  "bid_winner_id"
end  

What Am i doing wrong here ???

  • 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-18T06:39:23+00:00Added an answer on May 18, 2026 at 6:39 am

    You don’t need a custom method to accomplish this. Rails has a handy method called update_attribute:

    @post.update_attribute(:bid_winner_id,winner_id)
    

    which will work, but even that is not idiomatic Rails. If a Post is associated to the BidWinner model, and assuming you found (or created) a BidWinner and assigned it to @bid_winner), then you simply say:

    @post.bid_winner = @bid_winner
    @post.save
    

    One other thing — you aren’t really updating this via a GET, are you? That would generally not be a good thing.

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

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a bunch of posts stored in text files formatted in yaml/textile (from
We're building an app, our first using Rails 3, and we're having to build
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I am trying to loop through a bunch of documents I have to put

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.