Kevin
Kevin

Reputation: 1569

How do I use "button_to" to update a boolean

Preface: I'm still a beginner to web development, let alone rails so I'm constantly in over my head.

In my rails application, I have a boolean called "accepted" in "Bids."

On the show page for Bids, I am trying to create a button_to called "Accept Bid" that will, obviously, update the boolean from false to true, and then later, I will make it do a few other things. I experimented a bit with this but ended up getting so confused, I thought I would come here for some inspiration/push in the right direction.

Here's my bid.rb

    class Bid < ActiveRecord::Base

  belongs_to :user
  belongs_to :swarm_request

  # Accepts a bid for a swarm request
  def accept!
    self.swarm_request.update_attributes(:accepted => true)
    # also update the bid with any details here?
  end


end

Am I on the right track with this? Or should I create an action in the bids controller instead? Is using button_to the best way to do this? My apologies if I'm using incorrect jargon, or not being clear enough. Like I said, newb.

Thanks in advance for any help!

Upvotes: 0

Views: 1045

Answers (1)

Vasiliy Ermolovich
Vasiliy Ermolovich

Reputation: 24637

yes, it's ok to have skinny controller and fat model. you can read about this at http://weblog.jamisbuck.org/2006/10/18/skinny-controller-fat-model and i don't see anything wrong with button_to for this job.

Upvotes: 1

Related Questions