Hello All:
I am trying to create a select box that is filled with options based on
the user’s selection in a related drop-down. I have had success with
this before using the examples provided by the following two sources:
One posted by Rory at Rory on Rails - http://www.roryhansen.ca/?p=9
the other posted by Adam at
http://www.adamhegedus.com/articles/2006/01/19/ajaxed-select-boxes-in-rails
Here is my problem:
The user selects a Utility and a select with Receiving Points is updated
with the items related to the specific utility. Here is my code…
<>
def fill_rec_points
@lookups = Lookup.find_all_by_list_prompt(@params[:utility], :order
=> ‘list_item’)
render :partial => ‘rec_points’
#I use a partial here to fill the span so as not to mix View and
Business logic in the controller…
end
<>
Utility
<%= select ‘deal’, ‘utility’, %w{ PG&E SoCal SDG&E Southwest},
:include_blank => true %>
<span id="rec_point_list">
<label for="deal_rec_point">Receipt Point</label><br/>
<select id="deal[rec_point]" name="deal[rec_point]"></select>
</span>
<%= observe_field(“deal[utility]”,
:frequency => 0.25,
:update => “rec_point_list”,
:url => {:action => :fill_rec_points},
:with => “‘list_item=’+value”) %>
The problem seems to be that the controller is not picking anything up
from the @params[:utility] reference. I have tried every variation of
this I know (i.e. @params[‘deal’]['utility], @params[“utility”], etc.);
all to no avail.
I know everything is set up right with the prototype.js stuff because
when I manually enter the utility string in the controller (i.e.
‘SoCal’) instead of @params[:utility] (or whatever else I have tried),
it works great. I just can’t seem to get the user’s selection to pass to
my method. Any ideas?
One last thought…when I have gotten this to work before in other
projects I have passed an id integer and not a string like I am trying
to do now, so maybe I am referencing my @params wrong? Thanks to All and
sorry for a long post…