jQuery across models in Ruby on Rails -


i have rather simple ruby on rails application : 2 models lists , items. lists have many items , items belong lists. ok.

the show method of listscontroller prints page list of items belonging given list (in partial lists/_listofitems.html.erb). @ end of show.html.erb view, there form lets users add item list. in standard (no jquery) ror, works perfectly.

now, want let user add item list without reloading page. have managed jquery add item database problem refresh html list without reloading page. have managed have create.js.erb executed in itemscontroller , can make things appear on page problem create.js.erb lives in itemscontroller , not in listscontroller if try make create.js.erb render partial _listofitems.html.erb, fail since create.js.erb lives in itemscontroller , hence cannot access variables defined in show method of listscontroller.

i guess work charm if using index method of itemscontroller display list of items since living in there might yield further complications.

i hope clear. can me? thank much!

if understand right think solution lies in javascript + action in controller:

your show view should have ajax call follows, should triggered click/change/... jquery function, example: $("selector").change(function() { here ajax call placed })

  $.ajax( {     type: 'get',     url: "/ajax/somepageofyourown",     async: false,     data: { add here variables controller method need },     success: function( r ) {       $(' selector needs replaced ').html( r );     }   } ); 

add url ajax calls routes, controller responds

add controller action, should trigger renders html want replace previous html with.


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -