1

I need some help in figuring out how to set up a helper method and then call in in the view. What i need to do is update a single attribute of a model object.

How I plan to do this is to call a helper method Bid, which will update the attribute by the same increment every time, for example, by one dollar.

Then, I need a way to call this helper method in the view and update the auction attribute current_price and display it in the view. Any ideas on how this could be done? Thanks

  • 1
    Why do you want to do this in the view specifically? I assume you know this is a really bad practice. – Rudolf Nov 09 '14 at 21:41
  • Well I want to be able to display it in the view. Yes I know that.... Where should I put this method, and how can I call it in the view? That is the question – Clay McCullough Nov 09 '14 at 21:54
  • 1
    You would update the price in the controller and pass the `Bid` instance to the view. You then call something like `@bid.price` to access the price. – Rudolf Nov 09 '14 at 22:29
  • Right! What i tried to do was make a helper method in my auctions contoller that would update the current_price attribute on the auction. However, when I called it in the view, i kept getting a no method error... – Clay McCullough Nov 09 '14 at 23:09
  • Instead of having a object for bid, I thought it would be better to have an attribute on my specific auction and a helper method to alter that attribute. – Clay McCullough Nov 09 '14 at 23:11
  • So, did it solve your problem? I can submit it as an answer if you want ;) – Rudolf Nov 10 '14 at 13:38
  • Yes that solves this problem! Thank you. I will post my new problem. Thanks! – Clay McCullough Nov 10 '14 at 17:07

1 Answers1

1

Just update the price in the controller and pass the Bid instance to the view. In the view, you call something like:

@bid.price

To access the price of the current bid.

Rudolf
  • 1,856
  • 2
  • 19
  • 32