Thanks for any help you can provide! I've reviewed other topics related to this error but haven't been able to find a solution for my situation.
I've got an HTML form and two MYSQL database tables for my Ruby on Rails app. My first table has "masterlocations": points of interests with nicknames, IDs, and addresses. The form lets the user select a "masterlocation" by its nickname from a drop-down. My second table, newsavedmap, saves the masterlocation that the user selects.
My goal is to:
See if the masterlocation nickname selected in the dropdown matches the nickname of any of the masterlocations in my masterlocation database.
If so, I want to save the masterlocations's ID to @newsavedmap.start_masterlocation_id.
I think I'm almost there, but I'm getting the "ArgumentError (wrong number of arguments (2 for 1))" with my current code.
Controller
def create
@newsavedmap = Newsavedmap.new(params[:newsavedmap])
@masterlocation = Masterlocation.all
@newsavedmap.name = params[:newsavedmapname]
if !params[:starthere].blank?
@newsavedmap.start = params[:starthere]
else
@newsavedmap.start = params[:startthere]
@newsavedmap.start_masterlocation_id = @masterlocation.find(params[:id], :conditions => {:nickname => params[:startthere]})
end
if !params[:endhere].blank?
@newsavedmap.end = params[:endhere]
else
@newsavedmap.end = params[:endthere]
end
if !params[:waypointsselected].blank?
@waypoint = Waypoint.new(params[:waypoint])
@waypoint.waypoint = params[:waypointsselected]
@waypoint.newsavedmap = @newsavedmap
end
respond_to do |format|
if @newsavedmap.save
# flash[:notice] = 'The new map was successfully created.'
# format.html { redirect_to "/itineraries/#{@newsavedmap.itinerary_id}#showmaps" }
format.html { redirect_to "/maptry" }
format.xml { render :xml => @newsavedmap, :status => :created, :location => @newsavedmap }
else
format.html { render :action => "new" }
format.xml { render :xml => @newsavedmap.errors, :status => :unprocessable_entity }
end
if @waypoint.save
# flash[:notice] = 'The new map was successfully created.'
# format.html { redirect_to "/itineraries/#{@newsavedmap.itinerary_id}#showmaps" }
format.html { redirect_to "/maptry" }
format.xml { render :xml => @waypoint, :status => :created, :location => @waypoint }
else
format.html { render :action => "new" }
format.xml { render :xml => @waypoint.errors, :status => :unprocessable_entity }
end
end
end
ERROR CODE
Occurs in the line for @newsavedmap.start_masterlocation_id = @masterlocation.find(params[:id], :conditions => {:nickname => params[:startthere]})
ArgumentError (wrong number of arguments (2 for 1)):
app/controllers/newsavedmaps_controller.rb:66:in `find'
app/controllers/newsavedmaps_controller.rb:66:in `create'
UPDATE 1
Thanks to vinodadhikary, I've added the Masterlocation line below, but I updated it with => and a colon. However, the ID is not being saved to the database. Instead, the record's field updates with
--- []
CODE
def create
@newsavedmap = Newsavedmap.new(params[:newsavedmap])
@newsavedmap.name = params[:newsavedmapname]
if !params[:starthere].blank?
@newsavedmap.start = params[:starthere]
else
@newsavedmap.start = params[:startthere]
@newsavedmap.start_masterlocation_id = Masterlocation.find(:all, :conditions => { :id => params[:id], :nickname => params[:startthere]})
end