Syntactic Fructose
Syntactic Fructose

Reputation: 20104

pass helper url as unencoded to link_to url:

I'm trying to create a link using one of my helper paths like so:

<%= link_to url: admin_url(group) do %><i class="fa fa-eye"></i><% end %>

but it seems when rails renders the page, the elements looks like:

<a href="/admin?url=%2Fadmin%2F1%2Fedit"><i class="fa fa-pencil"></i></a>

how do I properly link to admin_url(group) ?

Upvotes: 0

Views: 52

Answers (1)

max
max

Reputation: 102240

<%= link_to admin_url(group) do %><i class="fa fa-eye"></i><% end %>

Passing a hash as the first argument is only done if you are using polymorphic routing instead of a route helper or literal path:

link_to(action: 'foo', controller: 'bar') do
  # name
end

Missing routes keys may be filled in from the current request's parameters (e.g. :controller, :action, :id and any other parameters that are placed in the path)

Which gives us /admin

url_for will then slurp up any non-reserved options like url and add them to the query string which is why you get /admin?url=%2Fadmin%2F1%2Fedit".

Upvotes: 1

Related Questions