# How to pass and not a parameter to a link?

**URL:** <https://www.ruby-forum.com/t/how-to-pass-and-not-a-parameter-to-a-link/157012>\
**Category:** Rails\
**Created:** [January 6, 2009, 1:56pm UTC](https://www.ruby-forum.com/t/how-to-pass-and-not-a-parameter-to-a-link/157012 "2009-01-06T13:56:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![xdmx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/53a042/32.png) [@xdmx](https://www.ruby-forum.com/u/xdmx)\
**Post date:** [January 6, 2009, 1:56pm UTC](https://www.ruby-forum.com/t/how-to-pass-and-not-a-parameter-to-a-link/157012/1 "2009-01-06T13:56:46Z")

</div>

Hi, i’ve a page where when a params[:something] is passed all/some the  
urls in that page must have the params[:something] too, but when there  
isn’t it shouldn’t appear.  
I’ve tried with:

report\_url(params[:id], :something =\> params[:something])  
this works when there is the params[:something], but it doesn’t when  
there isn’t, as the result is:  
[http://localhost:300/report/1?something=](http://localhost:300/report/1?something=)

So i’ve tried with  
tmp = params[:something] ? {:something =\> params[:something]} : {}  
report\_url(params[:id], tmp)

This is better, because works when there is the parameter, and almost  
does when there isn’t, as the result is:  
[http://localhost:300/report/1](http://localhost:300/report/1)?

Is there any way to have the two results  
[http://localhost:300/report/1?something=123](http://localhost:300/report/1?something=123) and  
[http://localhost:300/report/1](http://localhost:300/report/1) when there is and there isn’t the  
parameter? Without having the question mark at the end in the second  
case

---

<div class="post-metadata">

**Author:** ![xdmx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/53a042/32.png) [@xdmx](https://www.ruby-forum.com/u/xdmx)\
**Post date:** [January 12, 2009, 6:54pm UTC](https://www.ruby-forum.com/t/how-to-pass-and-not-a-parameter-to-a-link/157012/2 "2009-01-12T18:54:32Z")

</div>

anyone? ☹
