# &amp in url: this is driving me nuts!

**URL:** <https://www.ruby-forum.com/t/amp-in-url-this-is-driving-me-nuts/70845>\
**Category:** Rails\
**Created:** [October 3, 2006, 1:03pm UTC](https://www.ruby-forum.com/t/amp-in-url-this-is-driving-me-nuts/70845 "2006-10-03T13:03:06Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![remcoh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/c37758/32.png) [@remcoh](https://www.ruby-forum.com/u/remcoh)\
**Post date:** [October 3, 2006, 1:03pm UTC](https://www.ruby-forum.com/t/amp-in-url-this-is-driving-me-nuts/70845/1 "2006-10-03T13:03:06Z")

</div>

hi i have a weird problem:

this is my view:

\<%= start\_form\_tag :action =\> 'new\_beschikbaarheid', :behandelaar\_id =\>@behandelaar, :year =\> @year%\> behandelaar\<%= collection\_select("behandelaar",'id',Behandelaar.find(:all),:id,:naam) %\> \<%= submit\_tag 'Opzoeken' %\> \<%= end\_form\_tag %\>

when i hit the submit button i get this url:

[http://localhost:3000/admin/new\_beschikbaarheid?behandelaar\_id=1&amp;year=2006](http://localhost:3000/admin/new_beschikbaarheid?behandelaar_id=1&amp;year=2006)

where does the amp sign come from and better: how can i get rid of it:  
i sure hope someone can help me, i don’t know what to do anymore…

Regards,  
Remco

---

<div class="post-metadata">

**Author:** ![remcoh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/c37758/32.png) [@remcoh](https://www.ruby-forum.com/u/remcoh)\
**Post date:** [October 3, 2006, 1:07pm UTC](https://www.ruby-forum.com/t/amp-in-url-this-is-driving-me-nuts/70845/2 "2006-10-03T13:07:38Z")

</div>

i’m not sure of the details but i believe (just a hunch) the answer lies  
within the notorious ‘h’ - a protector for html code…

search rails for

h

sorry for not being more informative, maybe someone else out there can  
give u more specifics. . .

---

<div class="post-metadata">

**Author:** ![remcoh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/c37758/32.png) [@remcoh](https://www.ruby-forum.com/u/remcoh)\
**Post date:** [October 3, 2006, 1:17pm UTC](https://www.ruby-forum.com/t/amp-in-url-this-is-driving-me-nuts/70845/3 "2006-10-03T13:17:07Z")

</div>

thanks for trying,

unfortunately it doesn’t help

harp wrote:

> i’m not sure of the details but i believe (just a hunch) the answer lies  
> within the notorious ‘h’ - a protector for html code…
> 
> search rails for
> 
> h
> 
> sorry for not being more informative, maybe someone else out there can  
> give u more specifics. . .

---

<div class="post-metadata">

**Author:** ![remcoh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/c37758/32.png) [@remcoh](https://www.ruby-forum.com/u/remcoh)\
**Post date:** [October 3, 2006, 2:07pm UTC](https://www.ruby-forum.com/t/amp-in-url-this-is-driving-me-nuts/70845/4 "2006-10-03T14:07:30Z")

</div>

Remco Hh wrote:

> \<%= end\_form\_tag %\>
> 
> when i hit the submit button i get this url:
> 
> [http://localhost:3000/admin/new\_beschikbaarheid?behandelaar\_id=1&amp;year=2006](http://localhost:3000/admin/new_beschikbaarheid?behandelaar_id=1&amp;year=2006)
> 
> where does the amp sign come from and better: how can i get rid of it:  
> i sure hope someone can help me, i don’t know what to do anymore…

This is a known problem with some of the tag helpers that handle URLs  
– they double-escape the URL so that & becomes &amp; instead of  
just & in the HTML.

I’ve written a patch to fix this, but it’s not been accepted yet:

[http://dev.rubyonrails.org/ticket/5928](http://dev.rubyonrails.org/ticket/5928)

In the meantime you could work around it with some ugly code like this:

Alternatively you could write yourself a custom route so that the  
generated URL doesn’t contain any ampersands:

map.connect ‘:controller/new\_beschikbaarheid/:behandellar\_id/:year’

or something like that.

Chris

---

<div class="post-metadata">

**Author:** ![remcoh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/c37758/32.png) [@remcoh](https://www.ruby-forum.com/u/remcoh)\
**Post date:** [October 3, 2006, 2:11pm UTC](https://www.ruby-forum.com/t/amp-in-url-this-is-driving-me-nuts/70845/5 "2006-10-03T14:11:31Z")

</div>

Chris M. wrote:

> In the meantime you could work around it with some ugly code like this:

Google G. ate my code! But you get the idea – just manually write  
the form tag, and call url\_for to write the action attribute.

Chris

---

<div class="post-metadata">

**Author:** ![remcoh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/c37758/32.png) [@remcoh](https://www.ruby-forum.com/u/remcoh)\
**Post date:** [October 3, 2006, 2:15pm UTC](https://www.ruby-forum.com/t/amp-in-url-this-is-driving-me-nuts/70845/6 "2006-10-03T14:15:32Z")

</div>

> Remco Hh wrote:
> 
> > hi i have a weird problem:  
> > \<…\>  
> > when i hit the submit button i get this url:
> > 
> > [http://localhost:3000/admin/new\_beschikbaarheid?behandelaar\_id=1&amp;year=2006](http://localhost:3000/admin/new_beschikbaarheid?behandelaar_id=1&amp;year=2006)

Chris M.:  
\<…\>

> or something like that.

This bug should be fixed, but I’d suggest not to mix GET and POST  
(default) methods anyway. You can use hidden fields for additional  
parameters:

\<%= start\_form\_tag :action =\> 'new\_beschikbaarheid'%\> \<%= hidden\_field\_tag :behandelaar\_id, @behandelaar %\> \<%= hidden\_field\_tag :year, @year %\> behandelaar\<%= collection\_select("behandelaar",'id',Behandelaar.find(:all),:id,:naam) %\> \<%= submit\_tag 'Opzoeken' %\> \<%= end\_form\_tag %\>
## Regards, Rimantas

[http://rimantas.com/](http://rimantas.com/)

---

<div class="post-metadata">

**Author:** ![remcoh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/c37758/32.png) [@remcoh](https://www.ruby-forum.com/u/remcoh)\
**Post date:** [October 3, 2006, 2:29pm UTC](https://www.ruby-forum.com/t/amp-in-url-this-is-driving-me-nuts/70845/7 "2006-10-03T14:29:33Z")

</div>

Rimantas L. wrote:

> I’d suggest not to mix GET and POST  
> (default) methods anyway. You can use hidden fields for additional  
> parameters:

You’re not mixing GET and POST; you’re just POSTing to a URL that  
happens to have some querystring parameters. And, with Rails’ routes,  
the difference between

/user/edit/1

and

user/edit?id=1

is pretty slender. They both end up as params[:id] = 1. So every time  
you submit a form to /user/edit/1 (which is standard practice in  
Rails), you’re effectively POSTing to a URL with querystring  
parameters; it’s just that routing hides the ugliness of ?s, =s and &s.

Chris

---

<div class="post-metadata">

**Author:** ![remcoh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/c37758/32.png) [@remcoh](https://www.ruby-forum.com/u/remcoh)\
**Post date:** [October 3, 2006, 2:57pm UTC](https://www.ruby-forum.com/t/amp-in-url-this-is-driving-me-nuts/70845/8 "2006-10-03T14:57:39Z")

</div>

> Rimantas L. wrote:
> 
> > I’d suggest not to mix GET and POST  
> > (default) methods anyway. You can use hidden fields for additional  
> > parameters:
> 
> You’re not mixing GET and POST; you’re just POSTing to a URL that  
> happens to have some querystring parameters. And, with Rails’ routes,  
> the difference between

My bad, I should have said “I’d suggest to avoid passing parameters in  
url  
with POST” 🙂

## Regards, Rimantas

[http://rimantas.com/](http://rimantas.com/)

---

<div class="post-metadata">

**Author:** ![remcoh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/c37758/32.png) [@remcoh](https://www.ruby-forum.com/u/remcoh)\
**Post date:** [December 22, 2006, 1:36am UTC](https://www.ruby-forum.com/t/amp-in-url-this-is-driving-me-nuts/70845/9 "2006-12-22T01:36:58Z")

</div>

i just did this

```
  def url_for(options = {}, *parameters_for_method_reference)
    if options.kind_of? Hash
      options = { :only_path => true 

```

}.update(options.symbolize\_keys)  
escape = options.key?(:escape) ? options.delete(:escape) :  
true  
else  
escape = true  
end  
url = @controller.send(:url\_for, options,  
\*parameters\_for\_method\_reference)  
escape ? html\_escape(url).gsub(/&/,"&") : url # replaces  
the ‘&’ with its original &  
end

Aryk
