# Help with Forms

**URL:** <https://www.ruby-forum.com/t/help-with-forms/58144>\
**Category:** Rails\
**Created:** [April 18, 2006, 10:32pm UTC](https://www.ruby-forum.com/t/help-with-forms/58144 "2006-04-18T22:32:01Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![adam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/4af34b/32.png) [@adam](https://www.ruby-forum.com/u/adam)\
**Post date:** [April 18, 2006, 10:32pm UTC](https://www.ruby-forum.com/t/help-with-forms/58144/1 "2006-04-18T22:32:01Z")

</div>

Hello,

Ive been trying to sort out this problem for a couple of days now.

Here’s my problem:

Im builing an ajax form that has a repetitive sequence of similar form  
elements (tracking\_id).

\<%= text\_field “asset”, “tracking\_id”, “index” =\> i, “class” =\> “case”  
%\>  
\<%= text\_field “asset”, “tracking\_id”, “index” =\> i, “class” =\> “case”  
%\>  
\<%= text\_field “asset”, “tracking\_id”, “index” =\> i, “class” =\> “case”  
%\>

Im using the :index parameter as explained here \>\>  
[Peak Obsession](http://api.rubyonrails.com/classes/ActionView/Helpers/FormHelper.html).

My question is: How do I find all the records in the asset table that  
have the tracking\_id that was entered in the text field?

In my controller Im doing this:

```
 params[:asset].each_value do |prod|
 	records = Asset.find_all_by_tracking_id(prod)
 end

```

## However, this gives the error:

RuntimeError: ERROR C22P02 Minvalid input syntax for integer: "—

- tracking\_id
- “2202045"” Fnumutils.c L84 Rpg\_atoi: SELECT \* FROM asset WHERE  
(asset.“tracking\_id” = '—
- tracking\_id
- “2202045”’ )

* * *

How would I loop through and find each asset record? Any help is  
greatly appreciated. As you can tell, Im pretty new at using programming  
ruby.

Thanks.

---

<div class="post-metadata">

**Author:** ![adam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/4af34b/32.png) [@adam](https://www.ruby-forum.com/u/adam)\
**Post date:** [April 18, 2006, 11:16pm UTC](https://www.ruby-forum.com/t/help-with-forms/58144/2 "2006-04-18T23:16:25Z")

</div>

Adam wrote:

> ## However, this gives the error:
> 
> RuntimeError: ERROR C22P02 Minvalid input syntax for integer: "—

records = Asset.find\_all\_by\_tracking\_id(prod[:tracking\_id])

–  
We develop, watch us RoR, in numbers too big to ignore.

---

<div class="post-metadata">

**Author:** ![adam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/4af34b/32.png) [@adam](https://www.ruby-forum.com/u/adam)\
**Post date:** [April 18, 2006, 11:55pm UTC](https://www.ruby-forum.com/t/help-with-forms/58144/3 "2006-04-18T23:55:39Z")

</div>

Mark Reginald J. wrote:

> Adam wrote:
> 
> > ## However, this gives the error:
> > 
> > RuntimeError: ERROR C22P02 Minvalid input syntax for integer: "—
> 
> records = Asset.find\_all\_by\_tracking\_id(prod[:tracking\_id])
> 
> –  
> We develop, watch us RoR, in numbers too big to ignore.

That worked great!! Thanks alot Mark. I’ve been stuck on that all day.

When the form submits, Im trying to save a foreign key (medprocedure\_id)  
in the asset table for each of the tracking\_id’s in the form. Almost  
have it working, however, its not saving the foreign key for all the  
records. Only for the last one.

Heres what I have:

# Get the Tracking\_Ids from the form

```
 params[:asset].each_value do |prod|
 	@records = Asset.find_all_by_tracking_id(prod[:tracking_id])
 end

 @assets = []
 for record in @records
 @assets.insert(-1,{ 'record' => record})
 end

  # Now execute transaction and commit to db

  begin
  Asset.transaction(medproc) do

  # save new medprocedure entry
  medproc.save!

  # save link in join table (professionals)
  medproc.professionals << professional_record

 # save updated asset record
for asset in @assets
  asset['record'].medprocedure_id = medproc.id
  asset['record'].state_id = 12
  asset['record'].save!
end

  #raise "Exeception"
end
```

---

<div class="post-metadata">

**Author:** ![adam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/4af34b/32.png) [@adam](https://www.ruby-forum.com/u/adam)\
**Post date:** [April 19, 2006, 3:33am UTC](https://www.ruby-forum.com/t/help-with-forms/58144/4 "2006-04-19T03:33:31Z")

</div>

Mark Reginald J. wrote:

> But this will not use a different value of i for each tracking\_id field.  
> You need to do:
> 
> \<% 3.times do |i| %\>  
> \<%= text\_field “asset”, “tracking\_id”, “index” =\> i, “class” =\> “case”  
> %\>  
> \<% end %\>
> 
> Look at your development.log file to check that the right set of  
> parameters are being posted.

Mark,

I left that out intentionally. Sorry if it was confusing. I have the  
\<% #.times do |i| %\> logic in there.

When I view source in browser it looks good:

---

<div class="post-metadata">

**Author:** ![adam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/4af34b/32.png) [@adam](https://www.ruby-forum.com/u/adam)\
**Post date:** [April 19, 2006, 12:24am UTC](https://www.ruby-forum.com/t/help-with-forms/58144/5 "2006-04-19T00:24:02Z")

</div>

Adam wrote:

> When the form submits, Im trying to save a foreign key (medprocedure\_id)  
> in the asset table for each of the tracking\_id’s in the form. Almost  
> have it working, however, its not saving the foreign key for all the  
> records. Only for the last one.

In your original post you implied that you replicated the view line

\<%= text\_field “asset”, “tracking\_id”, “index” =\> i, “class” =\> “case”  
%\>

But this will not use a different value of i for each tracking\_id field.  
You need to do:

\<% 3.times do |i| %\>  
\<%= text\_field “asset”, “tracking\_id”, “index” =\> i, “class” =\> “case”  
%\>  
\<% end %\>

Look at your development.log file to check that the right set of  
parameters are being posted.

–  
We develop, watch us RoR, in numbers too big to ignore.

---

<div class="post-metadata">

**Author:** ![adam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/4af34b/32.png) [@adam](https://www.ruby-forum.com/u/adam)\
**Post date:** [April 19, 2006, 2:02pm UTC](https://www.ruby-forum.com/t/help-with-forms/58144/6 "2006-04-19T14:02:36Z")

</div>

Adam wrote:

> I left that out intentionally. Sorry if it was confusing. I have the  
> \<% #.times do |i| %\> logic in there.

OK, your problem is that you’re not accumulating your @records array  
properly. Instead of

```
  params[:asset].each_value do |prod|
  	@records = Asset.find_all_by_tracking_id(prod[:tracking_id])
  end

```

if an Asset can have multiple tracking ids, you need something like:

```
  @records = []
  params[:asset].each_value do |prod|
  	@records += Asset.find_all_by_tracking_id(prod[:tracking_id])
  end

```

Also, the subsequent construction of the @assets array looks to be  
superfluous.

–  
We develop, watch us RoR, in numbers too big to ignore.

---

<div class="post-metadata">

**Author:** ![adam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/4af34b/32.png) [@adam](https://www.ruby-forum.com/u/adam)\
**Post date:** [April 19, 2006, 5:51pm UTC](https://www.ruby-forum.com/t/help-with-forms/58144/7 "2006-04-19T17:51:45Z")

</div>

Mark Reginald J. wrote:

> OK, your problem is that you’re not accumulating your @records array  
> properly. Instead of
> 
> ```
> params[:asset].each_value do |prod|
> @records = Asset.find_all_by_tracking_id(prod[:tracking_id])
> end
> 
> ```
> 
> if an Asset can have multiple tracking ids, you need something like:
> 
> ```
> @records = []
> params[:asset].each_value do |prod|
> @records += Asset.find_all_by_tracking_id(prod[:tracking_id])
> end
> 
> ```
> 
> Also, the subsequent construction of the @assets array looks to be  
> superfluous.

Mark,

That worked perfectly. Thanks for all your help. I’ll have to research  
the += syntax.

Thanks Again!

Adam
