# How to access a form value in template from controller

**URL:** <https://www.ruby-forum.com/t/how-to-access-a-form-value-in-template-from-controller/113150>\
**Category:** Rails\
**Created:** [August 28, 2007, 4:46am UTC](https://www.ruby-forum.com/t/how-to-access-a-form-value-in-template-from-controller/113150 "2007-08-28T04:46:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![eggie5](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/7c8e57/32.png) [@eggie5](https://www.ruby-forum.com/u/eggie5)\
**Post date:** [August 28, 2007, 4:46am UTC](https://www.ruby-forum.com/t/how-to-access-a-form-value-in-template-from-controller/113150/1 "2007-08-28T04:46:54Z")

</div>

I have this in my template

\<%= hidden\_field(:content\_provider, :id, {:value =\> ‘1’}) %\>

How do I get it’s value (1) in my controller?

---

<div class="post-metadata">

**Author:** ![eggie5](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/7c8e57/32.png) [@eggie5](https://www.ruby-forum.com/u/eggie5)\
**Post date:** [August 28, 2007, 5:17am UTC](https://www.ruby-forum.com/t/how-to-access-a-form-value-in-template-from-controller/113150/2 "2007-08-28T05:17:55Z")

</div>

When you post the form to your controller you access that via,  
params[:content\_provider][:id]

---

<div class="post-metadata">

**Author:** ![eggie5](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/7c8e57/32.png) [@eggie5](https://www.ruby-forum.com/u/eggie5)\
**Post date:** [August 28, 2007, 5:27am UTC](https://www.ruby-forum.com/t/how-to-access-a-form-value-in-template-from-controller/113150/3 "2007-08-28T05:27:55Z")

</div>

I need to get the value of the hidden\_field before the page is  
rendered.

I’m sure it’s possible. I just want to set a variable in my view, and  
access it in my controller when the page is being built. In this case  
the variable is the hidden\_field’s value.

---

<div class="post-metadata">

**Author:** ![eggie5](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/7c8e57/32.png) [@eggie5](https://www.ruby-forum.com/u/eggie5)\
**Post date:** [August 28, 2007, 5:29am UTC](https://www.ruby-forum.com/t/how-to-access-a-form-value-in-template-from-controller/113150/4 "2007-08-28T05:29:56Z")

</div>

You can’t get it before the page is rendered, as it hasn’t been  
rendered yet? If your trying to use that to determine some kind of  
user state, then you should:  
a. Not put logic like that in a view  
b. Store a variable either in the url or in the session and pull it  
out of there to use in your controller method that creates this page.

Or if you really feel you must use this way, you could write an Ajax  
javascript post that would post it to the server. Either way you will  
need to post a form value to the server, you can’t “grab” those from  
your controller.  
What exactly are you trying to do, I’m not 100% sure your on the right  
track?

Cam
