# Getting input's value from a form

**URL:** <https://www.ruby-forum.com/t/getting-inputs-value-from-a-form/130365>\
**Category:** Rails\
**Created:** [February 27, 2008, 6:10pm UTC](https://www.ruby-forum.com/t/getting-inputs-value-from-a-form/130365 "2008-02-27T18:10:18Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![keaja](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/838e76/32.png) [@keaja](https://www.ruby-forum.com/u/keaja)\
**Post date:** [February 27, 2008, 6:10pm UTC](https://www.ruby-forum.com/t/getting-inputs-value-from-a-form/130365/1 "2008-02-27T18:10:18Z")

</div>

I am following a new tutorial just added to the upcoming book,  
Advanced Rails Recipes. The recipe is, “Process Recurring Credit Card  
Payments”. The tutorial is great and I recommend picking up the PDF  
book.

Simply put, there is a card server, and a then your main application  
which is used to pass credit card numbers to the server.

The problem I am having, is how do I get the parameters from the form  
into the controller without storing them in the model? It would be  
easy if I was storing the credit card number and expiration date in  
the user model, but I am not for security, so I cannot call  
@user.credit\_card number. I guess I need something like  
page["input\_credit\_card].value?

```
if @user.save
  self.current_user = @user
  cc = CreditCard.create(:first_name => @user.first_name,
    :last_name => @user.last_name,
    :number => #pick up from the form,
    :month => #pick up from the form,
    :year => #pick up from the form,
    :brand => #pickup from the form
  )
```

---

<div class="post-metadata">

**Author:** ![keaja](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/838e76/32.png) [@keaja](https://www.ruby-forum.com/u/keaja)\
**Post date:** [February 27, 2008, 6:48pm UTC](https://www.ruby-forum.com/t/getting-inputs-value-from-a-form/130365/2 "2008-02-27T18:48:06Z")

</div>

If you just want a CreditCard instance but do not want to persist it  
to the database you can use:-

CreditCard.new(:first\_name =\> @user.first\_name,  
:last\_name =\> @user.last\_name,  
:number =\> #pick up from the form,  
:month =\> #pick up from the form,  
:year =\> #pick up from the form,  
:brand =\> #pickup from the form )

Is that what you are asking or do you want to know how to pull the  
values out of the params hash?

Jabbslad

---

<div class="post-metadata">

**Author:** ![keaja](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/838e76/32.png) [@keaja](https://www.ruby-forum.com/u/keaja)\
**Post date:** [February 27, 2008, 6:55pm UTC](https://www.ruby-forum.com/t/getting-inputs-value-from-a-form/130365/3 "2008-02-27T18:55:13Z")

</div>

If I could get the values without persist to the database, that would  
be perfect. how can I do that?

---

<div class="post-metadata">

**Author:** ![keaja](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/838e76/32.png) [@keaja](https://www.ruby-forum.com/u/keaja)\
**Post date:** [February 27, 2008, 10:44pm UTC](https://www.ruby-forum.com/t/getting-inputs-value-from-a-form/130365/4 "2008-02-27T22:44:04Z")

</div>

thanks Jabbslad, I forgot about just using text\_field\_tag

---

<div class="post-metadata">

**Author:** ![keaja](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/838e76/32.png) [@keaja](https://www.ruby-forum.com/u/keaja)\
**Post date:** [February 27, 2008, 7:21pm UTC](https://www.ruby-forum.com/t/getting-inputs-value-from-a-form/130365/5 "2008-02-27T19:21:05Z")

</div>

You can just use the id of the tag to retrieve the value from the  
params hash, e.g.

Assuming you have something like this in your view:-

\<%= text\_field\_tag ‘number’ %\>

You should be able to access it in your controller using:-

:number =\> params[‘number’]

Is that what you were after?

Jabbslad
