Jason Tuttle
2006-Jul-12 18:16 UTC
[Rails] Can''t get observe_field to take a variable for a field name
The subject pretty much says it all: I can''t?get observe_field to take a variable for a field name I''ve tried: <%= observe_field(var_name, ... <%= observe_field("#{var_name}", ... <%= observe_field(:"#{var_name}", ... No luck. Am I missing something? Thanks, : ) Jason -- Posted via http://www.ruby-forum.com/.
Bill Walton
2006-Jul-12 18:33 UTC
[Rails] Can''t get observe_field to take a variable for a field name
Hi Jason, Jason Tuttle wrote:> The subject pretty much says it all: I can''t get > observe_field to take a variable for a field nameJust went through this myself, so I feel your pain ;-) It''ll work if your observe_field and the field you''re observing are in a partial and you pass the variable in as a local. I''ve included the my code below. hth, Bill ---- edit.rhtml (in part) ---- <%= render :partial => ''std_surgery_div'', :locals => {:surgery_name => name_underscored, :display_name => display_label, :checkbox_name => box_name, :datefield_name => field_name, :numeric_value => numeric_value, :checked_value => checked_value, :date_exists => checked_value, :surgery_date => date} %> ---- _std_surgery_div.rhtml ---- <div id=<%= surgery_name %> > <p><label><%= display_name %></label> <%= check_box_tag(checkbox_name, numeric_value, checked_value) %> <%= observe_field(checkbox_name, :url => {:action => ''update_std'', :id => surgery_name}) %> <% if date_exists == ''true'' %> Approx. Date: <%= text_field_tag(datefield_name, surgery_date, :size => 30) %> <%= observe_field(datefield_name, :url => {:action => ''update_date'', :id => surgery_name}, :with => "sdate" ) %> <% end %> </p> </div>
Jason Tuttle
2006-Jul-12 18:50 UTC
[Rails] Re: Can''t get observe_field to take a variable for a field n
> > Just went through this myself, so I feel your pain ;-) It''ll work if > your > observe_field and the field you''re observing are in a partial and you > pass > the variable in as a local.Thanks Bill! -- I really appreciate it!! : ) Jason -- Posted via http://www.ruby-forum.com/.