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

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Jay P. (Guest)
on 2008-10-07 09: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:

  <%= 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_for :booking, :url => {:action => :save_bookings} do |form|%>
  <div id="campsites">
    < "camp_id", Campsite.getAvailableCamps%>
        <%=submit_tag "Get Camp And Save"%>

<div id="campsites">
   <%=select "selected", "camp_id", @campholder %>

The problem is, no way in the world, I could get the selected campsite.
I tried[: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

This topic is locked and can not be replied to.