# What's the best way to pass string value from View to Controller?

**URL:** <https://www.ruby-forum.com/t/whats-the-best-way-to-pass-string-value-from-view-to-controller/124364>\
**Category:** Rails\
**Created:** [December 28, 2007, 2:12am UTC](https://www.ruby-forum.com/t/whats-the-best-way-to-pass-string-value-from-view-to-controller/124364 "2007-12-28T02:12:31Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![coolJay](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f19dbf/32.png) [@coolJay](https://www.ruby-forum.com/u/coolJay)\
**Post date:** [December 28, 2007, 2:12am UTC](https://www.ruby-forum.com/t/whats-the-best-way-to-pass-string-value-from-view-to-controller/124364/1 "2007-12-28T02:12:31Z")

</div>

I need to pass a string value from view to controller besides the  
form\_remote\_tag value…

What’s the best way to do it?

Is it possible to pass a parameter in send\_data method?

For instance, send\_data( channel\_info) ?

Currently, I have the code as follows… but I need to pass in the  
string value to controller with chat\_input value.

I can really figure out a clean way to do it.

Please let me know. Thanks~!

## View code…

\<%= form\_remote\_tag( :url =\> { :action =\> :send\_data }, :complete =\>  
“$(‘chat\_input’).value = ‘’” ) %\>  
\<%= text\_field\_tag( ‘chat\_input’, ‘’, { :size =\> 20, :id =\>  
‘chat\_input’} ) %\>  
\<%= submit\_tag “Add” %\>

## Controller code…

def send\_data  
…  
end

---

<div class="post-metadata">

**Author:** ![coolJay](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f19dbf/32.png) [@coolJay](https://www.ruby-forum.com/u/coolJay)\
**Post date:** [December 28, 2007, 2:17am UTC](https://www.ruby-forum.com/t/whats-the-best-way-to-pass-string-value-from-view-to-controller/124364/2 "2007-12-28T02:17:46Z")

</div>

You’re already doing it. you just just add more fields to the form  
depending  
on what information exactly you want to send to the page.

On Dec 28, 2007 11:42 AM, coolJay [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> “$(‘chat\_input’).value = ‘’” ) %\>
> 
> >

–  
Ryan B.

> **[frozenplague.net](http://www.frozenplague.net)**
>
> This domain may be for sale!

Feel free to add me to MSN and/or GTalk as this email.

---

<div class="post-metadata">

**Author:** ![coolJay](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f19dbf/32.png) [@coolJay](https://www.ruby-forum.com/u/coolJay)\
**Post date:** [December 28, 2007, 2:25am UTC](https://www.ruby-forum.com/t/whats-the-best-way-to-pass-string-value-from-view-to-controller/124364/3 "2007-12-28T02:25:58Z")

</div>

Ryan,

Thanks for you reply.

Actually, that’s what I am doing right now. But I want to make the  
information that is passed from view to controller invisible to user.

I acutally do have one more form\_remote\_tag field, which is

\<%= text\_field\_tag :channel\_info ,@channel, {:size=\>20} %\>

But doing it this way, it’s visible and modifiable to and by user. (I  
made diabled option turn on, then it wouldn’t let me pass the value in  
it)

Any other idea or suggestion?

Thanks~!

---

<div class="post-metadata">

**Author:** ![coolJay](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f19dbf/32.png) [@coolJay](https://www.ruby-forum.com/u/coolJay)\
**Post date:** [December 28, 2007, 2:40am UTC](https://www.ruby-forum.com/t/whats-the-best-way-to-pass-string-value-from-view-to-controller/124364/4 "2007-12-28T02:40:12Z")

</div>

coolJay wrote:

> \<%= text\_field\_tag :channel\_info ,@channel, {:size=\>20} %\>

See hidden\_field\_tag.  
[http://api.rubyonrails.com/classes/ActionView/Helpers/FormTagHelper.html#M001039](http://api.rubyonrails.com/classes/ActionView/Helpers/FormTagHelper.html#M001039)

---

<div class="post-metadata">

**Author:** ![coolJay](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f19dbf/32.png) [@coolJay](https://www.ruby-forum.com/u/coolJay)\
**Post date:** [December 28, 2007, 2:54am UTC](https://www.ruby-forum.com/t/whats-the-best-way-to-pass-string-value-from-view-to-controller/124364/5 "2007-12-28T02:54:00Z")

</div>

Robert,

Thank you for your help.

I am obviously a newbie to rails and web programing community as  
well…

Again Thanks~!

Jay

On 12¿ù28ÀÏ, ¿ÀÀü10½Ã40ºÐ, Robert H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![coolJay](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f19dbf/32.png) [@coolJay](https://www.ruby-forum.com/u/coolJay)\
**Post date:** [December 28, 2007, 11:47pm UTC](https://www.ruby-forum.com/t/whats-the-best-way-to-pass-string-value-from-view-to-controller/124364/6 "2007-12-28T23:47:49Z")

</div>

On 12/27/07, coolJay [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Any other idea or suggestion?

Way back in HTML 2.0 they invented the hidden field tag:

[http://www.w3.org/MarkUp/html-spec/html-spec\_8.html#SEC8.1.2.6](http://www.w3.org/MarkUp/html-spec/html-spec_8.html#SEC8.1.2.6)

In Rails it’s called hidden\_field or hidden\_field\_tag depending on  
your form setup:

[http://api.rubyonrails.com/classes/ActionView/Helpers/FormHelper.html#M000925](http://api.rubyonrails.com/classes/ActionView/Helpers/FormHelper.html#M000925)

[http://api.rubyonrails.com/classes/ActionView/Helpers/FormTagHelper.html#M001039](http://api.rubyonrails.com/classes/ActionView/Helpers/FormTagHelper.html#M001039)

–  
Greg D.  
[http://destiney.com/](http://destiney.com/)
