Rails remote delete and update view through Ajax -


in past, whenever wanted update part of view through ajax, i've done following:

  1. create partial out of part want update , give unique id, #tracks
  2. create special action in controller ajax call, remove_track updates values, etc. , add format.js
  3. create new js file same name action rails calls automatically remove_track.js.erb contains like: $('#tracks').html("<%=j render 'cds/show_tracks' %>");
  4. set remote: true in link calls action.

all fine, trying delete , update common index view using regular destroy method flexibility, meaning can call method either through ajax or normally. figured it's such common thing there has better way of above.

i can destroy method call destroy.js.erb file putting controller:

  format.js { layout: false } 

and of course setting remote: true on link.

what cannot view refresh. table want refresh encased in div unique id, since it's not partial, refuses refresh content. maybe i'm missing something.

am doomed have create partial , refresh method above or there more magical way of doing (other using turbolinks)?

thanks.

ps also, noticed has added disadvantage cannot pass rest of params destroy method since passes object id destroy using regular crud routes. if try use platform(action: destroy) or platform(method: delete) error:

no route matches {:action=>"destroy", :controller=>"platforms"} 

which means have create new route if want pass parameters...

yet disadvantage i'm repeading logic searches , sorting have in index method again in destroy method. definitely not way it.

thanks page:

http://carmennorahgraydean.blogspot.com.es/2012/10/rails-328-ajax-super-basic-example.html

i found proper way it. simple , effective.

hope helps else.


Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -

c# - String.format() DateTime With Arabic culture -