ruby on rails - Getting "wrong number of arguments" error on finder method -


i’m using rails 4.2.3 (and using mysql 5.5.37). i’m having difficulty writing finder method 1 of models. have columns “user,” “object,” , “day”, following

  def find_by_user_object_and_day     respond_to |format|       @current_user = user.find(session["user_id"])       format.js {         render :text => userobject.find_by_user_and_object_and_day(:user => @current_user, :object => params[:object], :day => params[:day])        }     end   end 

produces error

f, [2016-02-05t16:49:42.934112 #12058] fatal -- :  argumenterror (wrong number of arguments (given 1, expected 3)):   app/controllers/user_objects_controller.rb:77:in `block (2 levels) in find_by_user_object_and_day'   app/controllers/user_objects_controller.rb:74:in `find_by_user_object_and_day' 

how specify arguments finder method? haven’t explicitly defined finder method because thought “and” syntax work.

the error says:

argumenterror (wrong number of arguments (given 1, expected 3)) 

this means you're supposed pass in 3 distinct arguments, passed in 1. looks passed in hash of values instead of standalone values.

replace:

 userobject.find_by_user_and_object_and_day(:user => @current_user, :object => params[:object], :day => params[:day]) 

with this:

userobject.find_by_user_and_object_and_day(@current_user, params[:object], params[:day]) 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -