ruby on rails - argument error/wrong number of arguments - I have no idea what's going on here, -
i'm trying use paperclip , update listing whenever on form receive error.
argumenterror in listingscontroller#update wrong number of arguments (2 1)
code follows , line highlighted being @ fault begins if @listing.update(listing_params)
@listing = listing.new respond_to |format| if @listing.update(listing_params) format.html { redirect_to @listing, notice: 'listing updated.' } format.json { head :no_content } else
this application trace
app/controllers/listings_controller.rb:45:in `block in update' app/controllers/listings_controller.rb:44:in `update'
is there i'm missing, syntax-wise, or else? many thanks.
edit:
the code listings model (listings.rb) follows
class listing < activerecord::base has_attached_file :image, :styles => { :medium => "200x", :thumb => "100x100>" }, :default_url => "default.jpg" end
my form (_form.html.erb) follows:
<%= form_for @listing, :html => { :multipart => true } |f| %> <% if @listing.errors.any? %> <div id="error_explanation"> <h2><%= pluralize(@listing.errors.count, "error") %> prohibited listing being saved:</h2> <ul> <% @listing.errors.full_messages.each |msg| %> <li><%= msg %></li> <% end %> </ul> </div> <% end %> <div class="field"> <%= f.label :name %><br> <%= f.text_field :name, class: "form-control" %> </div> <div class="field"> <%= f.label :description %><br> <%= f.text_area :description, class: "form-control" %> </div> <div class="field"> <%= f.label :price %><br> <%= f.text_field :price, class: "form-control" %> </div> <div class="form-group"> <%= f.file_field :image, class: "form-control" %> </div> <div class="actions"> <%= f.submit class: "btn btn-primary" %> </div> <% end %>
you updating listing. need remove
@listing = listing.new
by writing initialising listing. it's update method hence need find listing not initialise new listing try
@listing = listing.find(params[:id]) #this find listing id respond_to |format| if @listing.update(listing_params) #this update listing find above format.html { redirect_to @listing, notice: 'listing updated.' } format.json { head :no_content } else #code end end
Comments
Post a Comment