&amp in url: this is driving me nuts!

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

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

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. . .

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. . .

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

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

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

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

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

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/

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

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” :slight_smile:

Regards,
Rimantas

http://rimantas.com/

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