ajax - Rails respond_with nothing? -


One of my controllers has an action action that answers AJAX and HTML requests. Inside the action I have set up a frequency variable (@location) using a find_or_initialize_by_such_and_such I check to see if the location already exists or is not using it:

 < Code> if @ location.id.nil? @ Location.save response_with (@location ,: location = & gt; root_path) do | Format | Format.html {redirect_to root_path} End End   

Originally partial (create.js.erb) works well with a newly saved place object in a list.

The problem occurs when the user inputs the location that already exists (i.e. ID). In this situation I do not want the search location to be added to the list, because it will be the cause of repetition (all the locations are already present). Since @ location.id.nil? lies in that scenario, the code is not clearly executed within the above block, but I am finding it hard to figure out how to handle that situation. I tried to do this:

  answer_ with (zero, place = & gt; root_path). Format | Format.html {redirect_to root_path} End   

But the js.erb file still captures the @location example variable and executes JavaScript that adds an object to the list.

So what would be the best way to work around this, in such cases where the object already created has been detected, whether Javascript will not execute the response to add this object to the list ?

remove

  response_with (zero, location = & gt; Root_path). Format | Format.html {redirect_to root_path} End   

and leave it only

  redirect_to root_path   

No additional response

Comments