# Brand newbie question relating to link\_to

**URL:** <https://www.ruby-forum.com/t/brand-newbie-question-relating-to-link-to/56092>\
**Category:** Rails\
**Created:** [March 28, 2006, 3:51am UTC](https://www.ruby-forum.com/t/brand-newbie-question-relating-to-link-to/56092 "2006-03-28T03:51:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![davidstokar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/4da419/32.png) [@davidstokar](https://www.ruby-forum.com/u/davidstokar)\
**Post date:** [March 28, 2006, 3:51am UTC](https://www.ruby-forum.com/t/brand-newbie-question-relating-to-link-to/56092/1 "2006-03-28T03:51:59Z")

</div>

I recently dived into Rails and am having trouble with the link\_to  
method.  
I’d like to pass some parameters to the action being called and am not  
sure  
how to do it. Essentially, I want to hyperlink a total count of bugs  
queried from the database to a method that will return the bug numbers  
when  
clicked on. I have a method, bug\_total, that returns the total number  
to  
display in the view. I have another method, total\_bugs, that will  
return  
the bugzilla url with all the bugid’s for that particular build when  
clicked.

Below is what I have in my view. I’d like to pass the  
:action=\>“total\_bugs”  
some parameters(build\_number, developer\_name, product\_name) based on the  
current build. I’ve tried many ways and haven’t been successfull, yet.  
Any  
help is greatly appreciated. Thanks!

\<%  
for build in @bugDashboard  
%\>  
  
\<%= link\_to build.bug\_total, {:controller =\> “dashboard”,  
:action =\> “total\_bugs”} %\>

…

---

<div class="post-metadata">

**Author:** ![davidstokar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/4da419/32.png) [@davidstokar](https://www.ruby-forum.com/u/davidstokar)\
**Post date:** [March 28, 2006, 4:02am UTC](https://www.ruby-forum.com/t/brand-newbie-question-relating-to-link-to/56092/2 "2006-03-28T04:02:01Z")

</div>

> \<%  
> for build in @bugDashboard  
> %\>  
>   
> \<%= link\_to build.bug\_total, {:controller =\> “dashboard”,  
> :action =\> “total\_bugs”} %\>
> 
> …

\<%= link\_to (build.bug\_total), :controller … %\>

that should work…

---

<div class="post-metadata">

**Author:** ![davidstokar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/4da419/32.png) [@davidstokar](https://www.ruby-forum.com/u/davidstokar)\
**Post date:** [March 28, 2006, 11:56pm UTC](https://www.ruby-forum.com/t/brand-newbie-question-relating-to-link-to/56092/3 "2006-03-28T23:56:49Z")

</div>

2006/3/27, David S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> \<%  
> for build in @bugDashboard  
> %\>  
>   
> \<%= link\_to build.bug\_total, {:controller =\> “dashboard”,  
> :action =\>  
> “total\_bugs”} %\>

Hmm, have you tried this ?

build\_number, developer\_name, product\_name  
\<%= link\_to build.bug\_total, :controller =\> “dashboard”, :action =\>  
“total\_bugs”, :build\_number =\> ‘123’, :developer\_name =\> ‘francois’,  
:product\_name =\> ‘rails’ %\>

#link\_to automatically makes any leftover parameters query parameters:

[1](https://www.ruby-forum.com/dashboard/total_bugs?build_number=123&developer_name=francois&product_name=rails)

In the action, you can access the parameters using the params Hash:

def total\_bugs  
params[:product\_name] # =\> “rails”  
params[:build\_number] # =\> “123”  
params[:developer\_name] # =\> “francois”  
end

NOTE: All parameters are strings in the params Hash.

When you are ready to explore routes, you can build a URL like this  
instead:

/dashboard/total\_bugs/rails/francois/123

map.connect  
‘/dashboard/total\_bugs/:product\_name/:developer\_name/:build\_number’,  
:controller =\> “dashboard”, :action =\> “total\_bugs”

which would give you the exact same params Hash as above.

Hope that helps !

---

<div class="post-metadata">

**Author:** ![davidstokar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/4da419/32.png) [@davidstokar](https://www.ruby-forum.com/u/davidstokar)\
**Post date:** [March 29, 2006, 2:16am UTC](https://www.ruby-forum.com/t/brand-newbie-question-relating-to-link-to/56092/4 "2006-03-29T02:16:49Z")

</div>

Thank you Francois! That worked great. I haven’t tried the route way,  
yet,  
but will when I get this thing up and running. You help is greatly  
appreciated!
