javascript - What is the correct way to use Rails JS templates? -


it's not clear me how use rails js templates well. they're replacing success callback on ajax request, right? why ever make sense separate js executed when request success js executes various other callbacks?

this of course assumes i'm binding click handler or link , making ajax request way. of course using link_to :remote => true. suppose in case might make sense use js templates. do if need handle other cases besides success? bind ajax:failure event link generated link_to? mean maintaining js related link in 2 separate places. , happens if there's 2 links (say, different markup) both make request action, each 1 requiring different js executed because need behave differently when clicked? how handle js template?

am thinking right?

i think best way avoid js templates. it's aberration try write js code in ruby... it's opinion, alternative cleaner , simpler because write code in actual language. so, write javascript makes call url provided in link, , ask content in json. in controller, return data in json (it can list of object data, or object like: {success: true} or {success: false}. in js treat object , make appropiate action. in different parts point same url can take different actions in js.


Comments