# Checking input data in the form when button clicked

**URL:** <https://www.ruby-forum.com/t/checking-input-data-in-the-form-when-button-clicked/150242>\
**Category:** Rails\
**Created:** [October 6, 2008, 1:28pm UTC](https://www.ruby-forum.com/t/checking-input-data-in-the-form-when-button-clicked/150242 "2008-10-06T13:28:36Z")\
**Posts on this page:** 1\
**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 6, 2008, 1:28pm UTC](https://www.ruby-forum.com/t/checking-input-data-in-the-form-when-button-clicked/150242/1 "2008-10-06T13:28:36Z")

</div>

Hi, I’m trying to check the data in the fields in the form and if valid  
save in the corresponding tables in the database. But (as I’m new to  
rails) just couldn’t figure out how I can do it. Here’s how I’m trying  
just to check the input data:

## IN CONTROLLER:

## class UserController \< ApplicationController def index end def update\_campsites @campholder=[] id=params[“walk\_id”] @camps=Campsite.find\_by\_sql(“select camp\_location from campsites where walk\_id=”+id) for eachcamp in @camps @campholder \<\< [eachcamp.camp\_location, eachcamp.camp\_location] end if request.post? @arrival=params[:arrival\_date] @nights=params[:nights] @children=params[:children] print @camp print @arrival print @nights print @children end end end

## IN VIEW: (index.rhtml)

# Great Walks Online Booking
 \<%= select(:selected, :id, GreatWalk.getAvailableLocations, {:prompt =\> 'Select a category'}, :id =\> :id\_selected) %\>

\<%= observe\_field :id\_selected, :url =\> {:action =\>  
:update\_campsites}, :update =\> :campsites, :with =\> “walk\_id” %\>

\<%form\_tag(:action=\>:update\_campsites) do %\> 

Campgrounds \<%=select "selected", "camp", Campsite.getAvailableCamps%\>

Arrival Date \<%=date\_select :arrival\_date, params[:arrival\_date]%\>

Nights \<%=text\_field\_tag :nights, params[:nights]%\>

Parents \<%=text\_field\_tag :parents, params[:parents]%\>

Children \<%=text\_field\_tag :children, params[:children]%\>

Total \<%=text\_field\_tag :total, params[:total]%\>

 \<%=submit\_tag "Calculate"%\> \<%end%\> --------------------------------------------------------------------------------
## IN VIEW: (update\_campsites.rhtml)

## \<%=select “selected”,“camp”,@campholder%\>

# I’m getting this error:

TypeError in UserController#update\_campsites  
can’t convert nil into String  
RAILS\_ROOT: C:/Users/Jay/Aptana/greatwalks

Application Trace | Framework Trace | Full Trace

Request  
Parameters:

{“authenticity\_token”=\>“7ab6ae4172e01c7cb2e7346ee13ce55548da1a7a”,  
“selected”=\>{“camp”=\>“Jabiru Swamp”},  
“arrival\_date”=\>{"(1i)"=\>“2008”,  
“(2i)”=\>“10”,  
“(3i)”=\>“6”},  
“nights”=\>“df”,  
“parents”=\>“klj”,  
“children”=\>“kj”,  
“total”=\>“kj”,  
“commit”=\>“Calculate”}

Show session dump

Response  
Headers:

# {“Cache-Control”=\>“no-cache”, “cookie”=\>[]}
