Forum: Ruby on Rails retrieve selected value from <%=select()%>

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Cdcdda30ac4e349c6ffd0819b9e1666f?d=identicon&s=25 Jay Pangmi (jaeezzy)
on 2008-10-07 07:13
Hi, I'm learning ruby on rails at the moment so please consider if this
is a silly problem. I have a index.rhtml file where the combo box lies.
When this combo box with different areas changes it updates another
combo box within the same file and displays all the campsites in that
area. For this I've written:

index.rhtml
--------------------------------------------------------------------------------
<form>
  <%= select(:selected, :location, GreatWalk.getAvailableLocations,
{:prompt => 'Select a category'}, :id => :id_selected) %>

  <%= observe_field :id_selected, :url => {:action =>
:update_campsites}, :update => :campsites, :with => "walk_id" %>
</form>
<%form_for :booking, :url => {:action => :save_bookings} do |form|%>
  <div id="campsites">
    <%=form.select "camp_id", Campsite.getAvailableCamps%>
  </div>
        <%=submit_tag "Get Camp And Save"%>
<%end%>
--------------------------------------------------------------------------------

update_campsites.rhtml
--------------------------------------------------------------------------------
<div id="campsites">
   <%=select "selected", "camp_id", @campholder %>
</div>
--------------------------------------------------------------------------------

The problem is, no way in the world, I could get the selected campsite.
I tried @booking=Booking.new(params[:booking]) and then (print
@booking.camp_id) in the save_bookings action in the controller, it
shows nil. I also tried putting @camp=params["selected"]["camp_id"] and
then (print @camp )in update_campsites action in controller but gives
error instead. Also after I click the button and change the first combo
box value it doesn't trigger any update to the second combo box. So,
please help me find what I'm doing wrong here and how I can get that
selected value, that would be so great. thanks

regards,
Jay
This topic is locked and can not be replied to.