Hi all, I start looking in unobtrusive javascript functionality in Rails 3. I couldn''t make any different when to use RJS vs pure Javascript template. For example: #RJS: page.replace_html, ''some_div'', :partial => ''some_partial'' #JS $("some_div").update("<%= escape_javascript(render(''some_partial'')) %>"); Could you point me some cases when they are used? Thanks, Samnang -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
I had problem with #JS template method, so I just use the inline javascript page.replace_html. The JS template wouldn''t update my DIV. Have you gotten the js template method working? On Tue, Oct 12, 2010 at 5:48 AM, Samnang <samnang.chhun-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi all, > > I start looking in unobtrusive javascript functionality in Rails 3. I > couldn''t make any different when to use RJS vs pure Javascript > template. > > For example: > #RJS: > page.replace_html, ''some_div'', :partial => ''some_partial'' > > #JS > $("some_div").update("<%= escape_javascript(render(''some_partial'')) > %>"); > > Could you point me some cases when they are used? > > Thanks, > Samnang > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Samnang wrote in post #949445:> Hi all, > > I start looking in unobtrusive javascript functionality in Rails 3. I > couldn''t make any different when to use RJS vs pure Javascript > template. > > For example: > #RJS: > page.replace_html, ''some_div'', :partial => ''some_partial'' > > #JS > $("some_div").update("<%= escape_javascript(render(''some_partial'')) > %>");Well, you should never ever be writing ERb in your JavaScript like that. JS files should IMHO always be static. I lean more toward writing my JavaScript directly, at least with Rails 2. But RJS might be nice for calling certain Ajax actions.> > Could you point me some cases when they are used? > > Thanks, > SamnangBest, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
The goodness of unobtrusiveness really shows when the project turns big and you have all your code separated, it allows easy maintenance, debugging and updates, imaging having all your styles in the html and the having to change the site''s look, lots of potential to brake code just for changing a little thing, same with obtrusive js. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 13 October 2010 03:15, Marnen Laibow-Koser <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Samnang wrote in post #949445: >> Hi all, >> >> I start looking in unobtrusive javascript functionality in Rails 3. I >> couldn''t make any different when to use RJS vs pure Javascript >> template. >> >> For example: >> #RJS: >> page.replace_html, ''some_div'', :partial => ''some_partial'' >> >> #JS >> $("some_div").update("<%= escape_javascript(render(''some_partial'')) >> %>"); > > Well, you should never ever be writing ERb in your JavaScript like that. > JS files should IMHO always be static.I''ve been looking at making a very JS heavy interface of late and it actually requires replacing sections of the page with dynamic content. Your take on it suggests that you could only ever return a static js script, and therefore have no dynamic content. Is that right?> > I lean more toward writing my JavaScript directly, at least with Rails > 2. But RJS might be nice for calling certain Ajax actions.The above examples merely do the same job with a cleaner syntax? Just trying to take a look at best practices and gauge what I would consider to be most appropriate. RobL -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Rob Lacey wrote in post #949724:> On 13 October 2010 03:15, Marnen Laibow-Koser <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> > wrote: >>> >>> #JS >>> $("some_div").update("<%= escape_javascript(render(''some_partial'')) >>> %>"); >> >> Well, you should never ever be writing ERb in your JavaScript like that. >> JS files should IMHO always be static. > > > I''ve been looking at making a very JS heavy interface of late and it > actually requires replacing sections of the page with dynamic content. > Your take on it suggests that you could only ever return a static js > script, and therefore have no dynamic content. Is that right?Not at all. You can have dynamic content with static JS files (search the list archives for more info -- I go through this discussion every couple of weeks :) ). My usual method is to have the JS read a hidden element that Rails puts in the DOM. Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.