From: Brian Candler Date: 2009-11-16T19:56:14+09:00 Subject: Re: erb and js question Derek Smith wrote: > Here is my code: > > cat login.html.erb > >
> <% form_tag :action => 'login' do %> >
> > <%= text_field_tag 'username' %> > > <%= password_field_tag 'password' %> > <%= image_submit_tag 'login.png' %> >
>
> <% end %> >
> > > Yet I am still unsure how to integrate this code, maybe just the JS > block? This isn't really a Ruby question, but briefly: you can emit a which does what you want. However: 1. You want this to happen when the page has finished loading, so write it to be triggered on the onload event. 2. It's cleaner to put it in the of your document, which could be in the layout or using content_for :head 3. It's cleaner to put it in a separate Javascript file, e.g. public/javascripts/focus_user.js, and then all you need is: <%= javascript_include_tag 'focus_user' %> This sort of stuff is wonderfully easy to do using jQuery, and I recommend it strongly. All you would need is: jQuery( function($) { $('#username').focus(); }); -- Posted via http://www.ruby-forum.com/.