Hi!
I am calling a controller's create action via ajax so when the object saves successfully, the js response is triggered. However, if the object fails to save due to validation, then I want the response to be html. I hope to achieve this by not returning the js response in the else block (please see code below) but this produces a 406 Not Acceptable error.
Any ideas on how to do this?
I should also probably note that the reason why I want to do this is because I am unsure how to create an appropriate js response if the validation fails...
Thanks in advance!!! =]
Controller create action
respond_to do |format|
if @person.save
flash[:notice] = 'Successfully created.'
format.html { redirect_to(@person) }
format.js
else
flash[:error] = 'There are errors while trying to create a new Person'
format.html { render :action => "new" }
end
end