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

Just went through this myself, so I feel your pain :wink: 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

Hi Jason,

Jason T. wrote:

The subject pretty much says it all: I can’t get
observe_field to take a variable for a field name

Just went through this myself, so I feel your pain :wink: 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 ----

>

<%= display_name %> <%= 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 %>

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs