"link_to" helper: Looking for no encoding in URLs

Hi you all,

I have a RESTful app where my link_to is something like
<%= link_to(“Trial”,sdrs_query_path(params[:id] + " = " +
my_transf(@value))) %>

When click on the link, the URL that appears is:
http://localhost:3007/sdrs/queries/vlan_interfaz%3DTrial

Is there anyway to avoid this? I want the equal sign as it is in the
URL.
Besides, the behaviour is strange. Even though the resulting URL is
this:
http://localhost:3007/sdrs/queries/vlan_interfaz%3DTrial

if I change it manually into the browser to this one:
http://localhost:3007/sdrs/queries/vlan_interfaz=Trial

it works the same. I mean, it’s great Rails encode URLs automatically,
but if there is no need (as in this case)…

PT 1: the “manual” URL “queries/vlan_interfaz=Trial” works even thoug
with query params such as “queries/vlan_interfaz=Trial?page=3”. This is
the reason why I say here there is no need in encoding.

PT 2: With a simple it does not happen. I would use this
way but my_transf(@value), a method that encodes “@value”, returns the
value as it is too, not encoded… :S

Thanks.

Hi,

your solution returns
/query/value

However, I want /query/key=value

The “to_sym” behaves the same :frowning:

Thorsten M. wrote:

this should work:

<%= link_to(“Trial”, sdrs_query_path(params[:id] => my_transf(@value))
%>

maybe you would have to use params[:id].to_sym, i’m not sure, if this
conversion is implicit

maybe your routing is different…
i used this with restful routing on an index action, that does not
expect any additional params
so:

<% test = {:id => “foo”}%>
<%= link_to(‘Test’, played_tracks_path(test[:id] => “bar”)) %>
returned the correct result with /played_tracks?foo=bar

but for the show action or any not restful routing it would fail that
way

if you have an index action, maybe:
sdrs_queries_path(…)
would work

this should work:

<%= link_to(“Trial”, sdrs_query_path(params[:id] => my_transf(@value))
%>

maybe you would have to use params[:id].to_sym, i’m not sure, if this
conversion is implicit

ok, i’m not sure, this is what you want (maybe you should post some more
info about your routing etc)

routes.rb:
map.resources :play_entries

view:
<% test = {:id => “foo”}%>
<% value = “bar”}%>
<%= link_to(‘Test’, play_entry_path(test[:id] + “=” + value)) %>

generates:

which would call the show action in my case…

I was doing that, but the result of link_to was:

Thorsten M. wrote:

ok, i’m not sure, this is what you want (maybe you should post some more
info about your routing etc)

routes.rb:
map.resources :play_entries

view:
<% test = {:id => “foo”}%>
<% value = “bar”}%>
<%= link_to(‘Test’, play_entry_path(test[:id] + “=” + value)) %>

generates:

which would call the show action in my case…

Um…your problem is different

I want to do something like query/:id
where :id may be “key=value”
You see? The entire url is a path URL, not a query URL.

On 13 Feb 2008, at 16:49, Damaris F. wrote:

PT 1: the “manual” URL “queries/vlan_interfaz=Trial” works even thoug
with query params such as “queries/vlan_interfaz=Trial?page=3”. This
is
the reason why I say here there is no need in encoding.

= is a reserved character in paths according to
http://www.ietf.org/rfc/rfc2396.txt
3.3
which probably means you shouldn’t use it like that. ‘It works’ isn’t
usually a good test for these sort of things. You may be relying upon
quirks of one particular web browser, server etc…

Fred

Hi all,
yes, you’re right, and I can try with another character.
The thing is that, for example, the character “|” is not a reserved
character in paths (I think), but Rails also encodes it.

Apart from that, there are a lot of apps that use these kind of
characters. See google, when you search for an image:
http://images.google.es/imgres?imgurl=http://www.lightworker.com/album/indexthumbs/alien_hello.gif&imgrefurl=http://profile.myspace.com/index.cfm%3Ffuseaction%3Duser.viewprofile%26friendid%3D76552036&h=300&w=300&sz=50&hl=es&start=3&um=1&tbnid=YRZ9kSX973HXCM:&tbnh=116&tbnw=116&prev=/images%3Fq%3DHello%26um%3D1%26hl%3Des%26sa%3DN

after the http://images.google… there is a “imgurl=http://…” I mean,
here they also use the character “/”, and it is not encoded.

Damaris F. wrote:

I was doing that, but the result of link_to was:

it worked in my case.
did you copy my example?

maybe it has to do with the routing and the kind of action. eg my
example worked on the index action, which does not need an id parameter.
your sdrs_query_path (singular path) should call the show action and
therefore expect the id as first parameter. in this case it may handle
things different.

or there are differences in the rails versions? i simply can’t reproduce
it in the way it works for you…

My Rails version is 1.2.5. I can reproduce your example programming an
“<a href=…” directly, but not with link_to. Link_to always encode my
characters.

Thorsten M. wrote:

Damaris F. wrote:

I was doing that, but the result of link_to was:

it worked in my case.
did you copy my example?

maybe it has to do with the routing and the kind of action. eg my
example worked on the index action, which does not need an id parameter.
your sdrs_query_path (singular path) should call the show action and
therefore expect the id as first parameter. in this case it may handle
things different.

or there are differences in the rails versions? i simply can’t reproduce
it in the way it works for you…

Yes, I thought I wouldn’t have problems cause I am not using the “?”, so
the “=” sign was not involved in any query variable :frowning: But well…

Xavier N. wrote:

On Feb 14, 2008, at 13:55 , Damaris F. wrote:

yes, you’re right, and I can try with another character.
The thing is that, for example, the character “|” is not a reserved
character in paths (I think), but Rails also encodes it.

In fact I am not 100% sure it is technically a reserved character
there. Let me explain.

The RFC says you first need to split the URL apart, and then interpret
reserved characters depending on the part of the URL you are dealing
with
. My interpretation as far as “=” is concerned is that first you
would split the URL by “?” and then interpret “=” in the query string.
Since AFAIK there’s no special meaning for “=” to the left of the
question mark I think technically it is not required to be escaped.

On Feb 14, 2008, at 13:55 , Damaris F. wrote:

yes, you’re right, and I can try with another character.
The thing is that, for example, the character “|” is not a reserved
character in paths (I think), but Rails also encodes it.

In fact I am not 100% sure it is technically a reserved character
there. Let me explain.

The RFC says you first need to split the URL apart, and then interpret
reserved characters depending on the part of the URL you are dealing
with
. My interpretation as far as “=” is concerned is that first you
would split the URL by “?” and then interpret “=” in the query string.
Since AFAIK there’s no special meaning for “=” to the left of the
question mark I think technically it is not required to be escaped.