Focus en un partial

encontre esto en valibuk.net » Focus On Form Element

la idea es en mi caso agregar una linea de detalle en un documento y
dejar
el curso en el primer campo de la linea recien agregada, la cosa va asi:

en el aplication_helper se agrega
module ApplicationHelper

def set_focus(id)
javascript_tag(“$(‘#{id}’).focus()”)
end

end

y en el partial en mi caso es _nuevo_detalle.rhtml

<% form_remote_for(:detalle, :url => new_detalle_path(@documento), :method => :put ) do |f| %> <%= (@documento.detalles.size + 1).to_s %> <%= f.text_field :cantidad, :size => 9, :maxlength => 9, :onkeypress => "return numeralsOnly(event)"%> <%= f.text_field :codigo, :size => 9, :maxlength => 9 %> <%= options_from_collection_for_select @productos, "id", "nombre" %> 0 0 <%= f.text_field :dscto, :size => 9, :maxlength => 9 %> 0 <%= link_to_remote image_tag('tick.png'), :submit => "det_0"%> <%= observe_field( :detalle_producto_id, :with => "'id='+value+'&cantidad='+$F('detalle_cantidad')", :frecuency => 0.5, :url => { :controller => :productos, :action => :show, :method => :get} ) %> <% end %> <%= set_focus 'detalle_cantidad' %>

la ultima linea es la que hace el trabajo.

espero no estar solo metiendo ruido.