ruby on rails - NoMethodError, undefined method 'bid' -


ive been trying call helper method controller on rails object , continue error. here code.

class auctionscontroller < applicationcontroller   helper_method :bid    def bid     @auction = @auction.update_attribute(:current_price == :current_price + 1.00)   end 

view

<%= link_to("bid", @auction.bid(auction) )%> 

stack trace

started "/auctions" 127.0.0.1 @ 2014-11-11 05:46:16 -0600 processing auctionscontroller#index html   auction load (1.7ms)  select "auctions".* "auctions"   rendered auctions/index.html.erb within layouts/spacelab (199.7ms) completed 500 internal server error in 234ms  actionview::template::error (undefined method `bid' nil:nilclass):     26:     <h3, class="textcolor"><%= auction.description %></h3><br />     27:     <h3, class="textcolor"><%= auction.start_time.strftime("opens on %b %d on %i:%m %p") %></h3><br /> 28:     <h3, class="textcolor"><%= auction.end_time.strftime("closes on %b %d on %i:%m %p") %></h3><br /> 29:     <%= link_to("bid", @auction.bid(auction) )%> 30:  31:         <%= link_to 'show', auction, class: "btn btn-primary btn-lg btn-block" %> 32:            app/views/auctions/index.html.erb:29:in `block in _02d262c45abda05ea87ddc9c2c9ec185'   app/views/auctions/index.html.erb:16:in `_02d262c45abda05ea87ddc9c2c9ec185'         rendered /users/claymccullough/.rvm/gems/ruby-2.0.0-p247/gems/actionpack-4.1.6/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (1.0ms)   rendered /users/claymccullough/.rvm/gems/ruby-2.0.0-p247/gems/actionpack-4.1.6/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (0.8ms)   rendered /users/claymccullough/.rvm/gems/ruby-2.0.0-p247/gems/actionpack-4.1.6/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb within rescues/layout (92.3ms) 

could tell me if code wrong or methodology incorrect? thanks

edit please see answer below, real problem...

you have missundertanding methods on controller, you're trying call controller method on object, can't that. methods on auctionscontroller part of controllers no part of class, if want add operations model class have write them in auction model

correct call controller, passing @auction parameter

<%= link_to("bid", @auction )%> 

Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -