# Sending "flags" with link\_to

**URL:** <https://www.ruby-forum.com/t/sending-flags-with-link-to/172415>\
**Category:** Rails\
**Created:** [July 21, 2009, 6:24am UTC](https://www.ruby-forum.com/t/sending-flags-with-link-to/172415 "2009-07-21T06:24:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![railslist](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/65b543/32.png) [@railslist](https://www.ruby-forum.com/u/railslist)\
**Post date:** [July 21, 2009, 6:24am UTC](https://www.ruby-forum.com/t/sending-flags-with-link-to/172415/1 "2009-07-21T06:24:38Z")

</div>

Let us say, I have a page with couple of links and i would like to send  
unique flag/variable settings through params for each these links when  
they are clicked.

For example:

A link clicked - flag ‘a’ sent  
B link clicked - flag ‘b’ sent

The exact scenario is that when the link is clicked, I have to perform a  
“find” to see if the params value exists in table 1 or 2 or 3…so on.

This is a very bad design and it is costly in terms of performance.

If I can set a flag/variable/indicator with each link, then I can  
straight away perform “find” in its corresponding table and execute the  
query.

Any pointers are more appreciated.

---

<div class="post-metadata">

**Author:** ![railslist](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/65b543/32.png) [@railslist](https://www.ruby-forum.com/u/railslist)\
**Post date:** [July 21, 2009, 9:45am UTC](https://www.ruby-forum.com/t/sending-flags-with-link-to/172415/2 "2009-07-21T09:45:31Z")

</div>

On Jul 21, 5:24 am, Rails L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> “find” to see if the params value exists in table 1 or 2 or 3…so on.
> 
> This is a very bad design and it is costly in terms of performance.

When you generate a link you either pass a hash of routing options  
(eg :controller =\> ‘foo’, :action =\> ‘…’) or you call one of the  
named route helpers (person\_path(…)) which can also take similar  
options. You can add any options you want (although the rails way  
these days would probably to make the table in question explicit in  
the url path itself rather than as a query parameter)

Fred

---

<div class="post-metadata">

**Author:** ![railslist](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/65b543/32.png) [@railslist](https://www.ruby-forum.com/u/railslist)\
**Post date:** [July 21, 2009, 3:48pm UTC](https://www.ruby-forum.com/t/sending-flags-with-link-to/172415/3 "2009-07-21T15:48:39Z")

</div>

you can always add extra parameter in link\_to

or link\_to\_remote … every method will allow you to send extra  
parameter  
to the controller in all cases whether you are using restful routing  
or not

for example:  
link\_to “a” ,{:controller=\>:your\_controller, :method  
=\> :your\_method , :flag=\>“a”}

or  
link\_to “a” , you\_controller\_path(:flag=\>“a”)

On Jul 21, 10:24 am, Rails L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
