开发者

How do I use "button_to" to update a boolean

开发者 https://www.devze.com 2023-02-21 08:21 出处:网络
Preface:I\'m still a beginner to web development, let alone rails so I\'m constantly in over my head.

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 la开发者_StackOverflowter, 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!


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号