# How to get value from partial

**URL:** <https://www.ruby-forum.com/t/how-to-get-value-from-partial/150586>\
**Category:** Rails\
**Created:** [October 10, 2008, 7:38am UTC](https://www.ruby-forum.com/t/how-to-get-value-from-partial/150586 "2008-10-10T07:38:41Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![jicksta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7ba0ec/32.png) [@jicksta](https://www.ruby-forum.com/u/jicksta)\
**Post date:** [October 10, 2008, 7:38am UTC](https://www.ruby-forum.com/t/how-to-get-value-from-partial/150586/1 "2008-10-10T07:38:41Z")

</div>

Hi, I’m really confused on how I should do it as I have a form as:

================================================================================  
\<%form\_for :cart do |form|%\>

Campgrounds  
 \<%= form.select "campsite", %w{ ---- }, :class =\> "select\_campsites" %\>

Arrival Date:  
 \<%= form.text\_field :arrival\_date %\>

Nights:  
 \<%= form.text\_field :nights %\>

Parents:  
 \<%= form.text\_field :parents %\>

Children:  
 \<%= form.text\_field :children %\>

Family Rate:  
 \<%= form.check\_box "family\_claim",{}, "1", "0"%\>

# \<%=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

Campgrounds  
 \<%=select "camp", "id", @resultset %\>

================================================================================

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.

---

<div class="post-metadata">

**Author:** ![jicksta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7ba0ec/32.png) [@jicksta](https://www.ruby-forum.com/u/jicksta)\
**Post date:** [October 10, 2008, 1:18pm UTC](https://www.ruby-forum.com/t/how-to-get-value-from-partial/150586/2 "2008-10-10T13:18:05Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![jicksta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7ba0ec/32.png) [@jicksta](https://www.ruby-forum.com/u/jicksta)\
**Post date:** [October 10, 2008, 2:04pm UTC](https://www.ruby-forum.com/t/how-to-get-value-from-partial/150586/3 "2008-10-10T14:04:50Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jicksta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7ba0ec/32.png) [@jicksta](https://www.ruby-forum.com/u/jicksta)\
**Post date:** [October 10, 2008, 2:51pm UTC](https://www.ruby-forum.com/t/how-to-get-value-from-partial/150586/4 "2008-10-10T14:51:00Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![jicksta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7ba0ec/32.png) [@jicksta](https://www.ruby-forum.com/u/jicksta)\
**Post date:** [October 10, 2008, 3:14pm UTC](https://www.ruby-forum.com/t/how-to-get-value-from-partial/150586/5 "2008-10-10T15:14:44Z")

</div>

On Oct 10, 1:38 am, Jay P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> # \_campsites.rhtml
> 
> Campgrounds  
> \<%=select "camp", "id", @resultset %\>
> 
> ================================================================================

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 removed\_email\_address@domain.invalid  
To unsubscribe from this group, send email to  
removed\_email\_address@domain.invalid  
For more options, visit this group at  
[http://groups.google.com/group/rubyonrails-talk?hl=en](http://groups.google.com/group/rubyonrails-talk?hl=en)  
-~----------~----~----~----~------~----~------~–~—

---

<div class="post-metadata">

**Author:** ![jicksta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7ba0ec/32.png) [@jicksta](https://www.ruby-forum.com/u/jicksta)\
**Post date:** [October 10, 2008, 3:41pm UTC](https://www.ruby-forum.com/t/how-to-get-value-from-partial/150586/6 "2008-10-10T15:41:33Z")

</div>

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

 with this partial. So, couldn’t get  
thru…

---

<div class="post-metadata">

**Author:** ![jicksta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7ba0ec/32.png) [@jicksta](https://www.ruby-forum.com/u/jicksta)\
**Post date:** [October 10, 2008, 3:16pm UTC](https://www.ruby-forum.com/t/how-to-get-value-from-partial/150586/7 "2008-10-10T15:16:29Z")

</div>

On Oct 10, 1:38 am, Jay P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
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
