I have a rails3.1 application where I will send some data to client. One way of doing it is a jscon call and then use jquery on client to add the json data to page. but I am sending a javascript code directly from view i.e, adding css classes and ids from view and just sending the annotated data to client.
something like this in js.erb file
$(“#posts”).append(” “);
$(“#posts”).data(‘totalPosts’, <%= @postCounter %>);
My question is Are there any potential issues with this approach? Any security risks or browser issues?
Thanks,
Anish
It will work, but isn’t so great from a maintainability / system engineering point of view:
Suggestion: switch to an api. Make your Rails app into a service that serves up json. Write jQuery and regular Javascript on the client to interact with with the services provided by your Rails app.
You can also use new compact libs on the browser that make this easy and fun. I’m liking AngularJS, for instance.