# Newbie: accessing form parameters in controller action?

**URL:** <https://www.ruby-forum.com/t/newbie-accessing-form-parameters-in-controller-action/115272>\
**Category:** Rails\
**Created:** [September 22, 2007, 11:49pm UTC](https://www.ruby-forum.com/t/newbie-accessing-form-parameters-in-controller-action/115272 "2007-09-22T23:49:55Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![tharrisx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e19adc/32.png) [@tharrisx](https://www.ruby-forum.com/u/tharrisx)\
**Post date:** [September 22, 2007, 11:49pm UTC](https://www.ruby-forum.com/t/newbie-accessing-form-parameters-in-controller-action/115272/1 "2007-09-22T23:49:55Z")

</div>

Newbie alert!

I am saving a form, and in my save action in the controller, I can do

logger.info(params)

and see a string in the log like

“commitSaveactionsavecontrollerfoofooattrib1value1attrib2value2…”

which is all of the info from my form, controller (foo), action (save),  
model (foo), and attribute values. It’s all there, but how do I get at  
it?

I would like to get at the attribute values (form fields) discretely,  
and thought I could do something like

logger.info(params[:attrib1])

which might return

value1

But it doesn’t seem to return anything. Several other newbie attempts  
to query params fail too. What gives?

Sorry to be a dunce.

Tom

---

<div class="post-metadata">

**Author:** ![tharrisx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e19adc/32.png) [@tharrisx](https://www.ruby-forum.com/u/tharrisx)\
**Post date:** [September 23, 2007, 12:04am UTC](https://www.ruby-forum.com/t/newbie-accessing-form-parameters-in-controller-action/115272/2 "2007-09-23T00:04:17Z")

</div>

That should work ok. Try this to inspect them easier in your logs:

logger.debug params.inspect

That should help you I think.

---

<div class="post-metadata">

**Author:** ![tharrisx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e19adc/32.png) [@tharrisx](https://www.ruby-forum.com/u/tharrisx)\
**Post date:** [September 23, 2007, 12:29am UTC](https://www.ruby-forum.com/t/newbie-accessing-form-parameters-in-controller-action/115272/3 "2007-09-23T00:29:49Z")

</div>

Thanks William.

So in a non-contrived case I logger.debug params.inspect returns

{“commit”=\>“Add Comment”, “action”=\>“save\_comment”,  
“controller”=\>“survey”, “survey”=\>{“new\_comment\_body”=\>“My Comment”,  
“survey\_id”=\>“1”, “new\_comment\_title”=\>“My Title”}}

None of these variants, starting one line later in the same method  
produces anything in the log (perhaps a newline?)

```
logger.debug params[:new_comment_title]
logger.debug "#{params[:new_comment_title]}"
logger.debug "#{params['new_comment_title']}"

```

I am missing something stupid … but what?

Thanks –

Dunce Boy Tom

---

<div class="post-metadata">

**Author:** ![tharrisx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e19adc/32.png) [@tharrisx](https://www.ruby-forum.com/u/tharrisx)\
**Post date:** [September 23, 2007, 12:47am UTC](https://www.ruby-forum.com/t/newbie-accessing-form-parameters-in-controller-action/115272/4 "2007-09-23T00:47:58Z")

</div>

Tom H.on wrote:

> So in a non-contrived case I logger.debug params.inspect returns
> 
> {“commit”=\>“Add Comment”, “action”=\>“save\_comment”,  
> “controller”=\>“survey”, “survey”=\>{“new\_comment\_body”=\>“My Comment”,  
> “survey\_id”=\>“1”, “new\_comment\_title”=\>“My Title”}}

new\_comment\_title is inside the survery hash:  
params[:survey][:new\_comment\_title]

Fred

---

<div class="post-metadata">

**Author:** ![tharrisx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e19adc/32.png) [@tharrisx](https://www.ruby-forum.com/u/tharrisx)\
**Post date:** [September 23, 2007, 12:53am UTC](https://www.ruby-forum.com/t/newbie-accessing-form-parameters-in-controller-action/115272/5 "2007-09-23T00:53:20Z")

</div>

Here is the deal, the key “new\_comment\_title” is actually in the hash  
pointed to by “survey” so you would access it like this:

logger.debug params[:survey][:new\_comment\_title]

---

<div class="post-metadata">

**Author:** ![tharrisx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e19adc/32.png) [@tharrisx](https://www.ruby-forum.com/u/tharrisx)\
**Post date:** [September 23, 2007, 2:53am UTC](https://www.ruby-forum.com/t/newbie-accessing-form-parameters-in-controller-action/115272/6 "2007-09-23T02:53:04Z")

</div>

William P. wrote:

> Here is the deal, the key “new\_comment\_title” is actually in the hash  
> pointed to by “survey” so you would access it like this:
> 
> logger.debug params[:survey][:new\_comment\_title]

William & Fred –

Aha! (Doh!)

Thanks. No, really, thanks. My wife thanks you, too, since I was  
obsessively trying different things that didn’t work.

Tom
