javascript - Rails and ajax: confusion about callback -


i'm confused ajax request in rails.

i'm submitting form using ajax , fine. must handle callback, but...

following tutorials hint add

respond_to |format|    format.js end 

to controler#create , place in views folder "create.js.erb" response.

other tutorials suggest create js file in assets folder , handle callback js file.

what's difference? , what's right way?

both different ways handling callback of ajax request. suggest use js.erb file handle ajax callback because file can recognize both js ruby code , execute.

for example,

in controller,

def create 

...

  if    @foo = true   else    @foo = false   end 

in create.js.erb, can done want show/hide div based on @foo value, can write like,

<% if @foo %>   // js code <% else %>  // else <% end %> 

while if create js file in assets folder not able write condition above because pure js file , creating js.erb easy way handle ajax response.


Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -

php - $params->set Array between square bracket -