I am trying to run a javascript line from my controller as a response to an AJAX call :
respond_to do |format|
if params[:return_to] == 'monthly_calendar'
render js: "alert('hey Trip!');"
else
format.js { render :partial => @task, layout: false }
format.html { redirect_to things_url }
format.json { render :json => @object.to_json }
format.xml do
if @task.new_record?
render :xml => @task.errors.to_xml
else
render :xml => @task.to_xml, :status => '201 Created'
end
end
end
Instead this returns a 406. Any ideas?
It most certainly goes to the correct call in this statement. But doesn’t know what to do with the javascript call, and returns a 406.
Change it to this
Because you are not specifying to what format are you responding, e.g. format.html { #your code here } when params[:return_to] == ‘monthly_calendar’. Check documentation of respond_to for more information.