Forum: Ruby on Rails how to get value from partial

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-10 07:38
Hi, I'm really confused on how I should do it as I have a form as:

================================================================================
<%form_for :cart do |form|%>
  <div id ="campsites_list" >
      <p>
           <label for = "camp location">Campgrounds</label><br />
           <%= form.select "campsite", %w{ ---- }, :class =>
"select_campsites" %>
      </p>
  </div>
  <p>
    <label for = "arrival date">Arrival Date:</label><br />
    <%= form.text_field :arrival_date %>
  </p>
  <p>
    <label for = "nights">Nights:</label><br />
    <%= form.text_field :nights %>
  </p>
  <p>
    <label for = "parents">Parents:</label><br />
    <%= form.text_field :parents %>
  </p>
  <p>
    <label for = "children">Children:</label><br />
    <%= form.text_field :children %>
  </p>
  <p>
    <label for = "family claim">Family Rate:</label><br />
    <%= form.check_box "family_claim",{}, "1", "0"%>
  </p>

  <%=submit_tag "Calculate"%>
<%end%>
================================================================================

Now div with the :id "campsites_list" gets updated with the
_campsites.rhtml partial when ever I change the value of another combo
box.

_campsites.rhtml
================================================================================
<p>
  <label for="camp location">Campgrounds</label><br/>
  <%=select "camp", "id", @resultset %>
</p>
================================================================================

I'm trying to save all the above details with
@cart=Cart.new(params[:cart]) all gets saved except the value from the
combo box so how can I save it as well... thanks.
Cdcdda30ac4e349c6ffd0819b9e1666f?d=identicon&s=25 Jay Pangmi (jaeezzy)
on 2008-10-10 13:18
Or is it possible that i get all the textfield values from params[:cart]
and the value of the combo box with params[:camp][:id] and squeeze them
together and pass to Cart.new(squeezed_object)
thanks..
D188e591eac11021329b8821a5f954c7?d=identicon&s=25 Ar Chron (railsdog)
on 2008-10-10 14:04
Could it be that your select for "camp" isn't part of the form?

View source for your page in the browser to make sure that your select
is indeed part of the form, and that data should come back to you.
Cdcdda30ac4e349c6ffd0819b9e1666f?d=identicon&s=25 Jay Pangmi (jaeezzy)
on 2008-10-10 14:51
Ar Chron wrote:
> Could it be that your select for "camp" isn't part of the form?
>
> View source for your page in the browser to make sure that your select
> is indeed part of the form, and that data should come back to you.

Ya, I couldn't find it in the view source. I loaded that partial with
updated values and then viewed the source but still its showing the code
for the previous combo box only..
49de4cd2f26705785cbef2b15a9df7aa?d=identicon&s=25 Nick (Guest)
on 2008-10-10 15:14
(Received via mailing list)
On Oct 10, 1:38 am, Jay Pangmi <rails-mailing-l...@andreas-s.net>
wrote:
> _campsites.rhtml
> ================================================================================
> <p>
>   <label for="camp location">Campgrounds</label><br/>
>   <%=select "camp", "id", @resultset %>
> </p>
> ================================================================================

Shouldn't the select field in the partial be part of the form? IE:
<%= form.select "camp", "id", @resultset %>

Notice the "<%= form.select" in comparison to the original "<
%=select".

Hope that helps.
-Nick
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
49de4cd2f26705785cbef2b15a9df7aa?d=identicon&s=25 Nick (Guest)
on 2008-10-10 15:16
(Received via mailing list)
On Oct 10, 1:38 am, Jay Pangmi <rails-mailing-l...@andreas-s.net>
wrote:
>     <label for = "arrival date">Arrival Date:</label><br />
>     <%= form.text_field :arrival_date %>

By the way, you should also use the #label method, like this:

<%= form.label :arrival_date, 'Arrival Date:' %>

Cheers,
Nick
Cdcdda30ac4e349c6ffd0819b9e1666f?d=identicon&s=25 Jay Pangmi (jaeezzy)
on 2008-10-10 15:41
Nick wrote:

> Shouldn't the select field in the partial be part of the form? IE:
> <%= form.select "camp", "id", @resultset %>
>
> Notice the "<%= form.select" in comparison to the original "<
> %=select".
>
> Hope that helps.
> -Nick

<%= form.select "camp", "id", @resultset %> is an error coz the word
form is no where to be found in the _campsites.rhtml. I tried using
<%form_for :cart do |form|%><%end%> in partial file as well, but that
stopped the updating of the <div> with this partial. So, couldn't get
thru..
This topic is locked and can not be replied to.