# Local variable

**URL:** <https://www.ruby-forum.com/t/local-variable/184871>\
**Category:** Rails\
**Created:** [March 9, 2010, 7:23pm UTC](https://www.ruby-forum.com/t/local-variable/184871 "2010-03-09T19:23:42Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![kevid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/e480ec/32.png) [@kevid](https://www.ruby-forum.com/u/kevid)\
**Post date:** [March 9, 2010, 7:23pm UTC](https://www.ruby-forum.com/t/local-variable/184871/1 "2010-03-09T19:23:42Z")

</div>

Hi all,

Please, is it possible passing a local variable (specifically of type  
“integer”) from a view to controller using the “link\_to” function

in rails.

All answers are appreciated.

---

<div class="post-metadata">

**Author:** ![kevid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/e480ec/32.png) [@kevid](https://www.ruby-forum.com/u/kevid)\
**Post date:** [March 9, 2010, 7:31pm UTC](https://www.ruby-forum.com/t/local-variable/184871/2 "2010-03-09T19:31:55Z")

</div>

On Tue, Mar 9, 2010 at 10:22 AM, kevid [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Please, is it possible passing a local variable (specifically of type  
> “integer”) from a view to controller using the “link\_to” function  
> in rails.
> 
> All answers are appreciated.

Have you read the API doc for link\_to ? Your answer is there 🙂

(though HTTP request parameters are going to be strings, always)

–  
Hassan S. ------------------------ removed\_email\_address@domain.invalid  
twitter: @hassan

---

<div class="post-metadata">

**Author:** ![kevid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/e480ec/32.png) [@kevid](https://www.ruby-forum.com/u/kevid)\
**Post date:** [March 9, 2010, 7:36pm UTC](https://www.ruby-forum.com/t/local-variable/184871/3 "2010-03-09T19:36:01Z")

</div>

thanks,

pls can you post the link?

On Mar 9, 7:30 pm, Hassan S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![kevid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/e480ec/32.png) [@kevid](https://www.ruby-forum.com/u/kevid)\
**Post date:** [March 9, 2010, 8:46pm UTC](https://www.ruby-forum.com/t/local-variable/184871/4 "2010-03-09T20:46:51Z")

</div>

kevid wrote:

> pls can you post the link?

> **[ActionView::Helpers::UrlHelper](https://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#M001597)**
>
> Provides a set of methods for making links and getting URLs that depend on the routing subsystem (see ActionDispatch::Routing).

> Please, is it possible passing a local variable (specifically of type  
> “integer”) from a view to controller using the “link\_to” function

Although, this is not passing a local variable from the view to the  
controller. The link\_to helper will generate a new request/response  
cycle. Any context you had will be lost, which is why your value must be  
passed as either part of the query string or as form data.

Example from the above doc reference:

link\_to “Nonsense search”, searches\_path(:foo =\> “bar”, :baz =\>  
“quux”)

# =\> [Nonsense search](https://www.ruby-forum.com/searches?foo=bar&baz=quux)

As noted by Hassan when you read your value from the params hash it will  
be a string. Use params[:my\_value].to\_i to get your FixNum value from  
inside your controller action.

---

<div class="post-metadata">

**Author:** ![kevid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/e480ec/32.png) [@kevid](https://www.ruby-forum.com/u/kevid)\
**Post date:** [March 12, 2010, 8:27am UTC](https://www.ruby-forum.com/t/local-variable/184871/5 "2010-03-12T08:27:23Z")

</div>

request parameters are always strings.

You can convert string parameter to integer in controller using  
_to\_i_method.

On Wed, Mar 10, 2010 at 1:16 AM, Robert W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> controller. The link\_to helper will generate a new request/response  
> be a string. Use params[:my\_value].to\_i to get your FixNum value from  
> .  
> For more options, visit this group at  
> [http://groups.google.com/group/rubyonrails-talk?hl=en](http://groups.google.com/group/rubyonrails-talk?hl=en).

–  
Sandip

* * *

> **[Fun On Rails](http://funonrails.com/)**
>
> Journal of a Web Developer #ruby #rails #JS
