Rails: Route ignoring parameter
I am using the below to render a collection:
<%= render :partial => 'mini_release', collection: group, as: :r %>
And the following routes:
constraints(domain: /[a-zA-Z0-9-]+/i, page: /[0-9]+/, :format => 'html') do
get ':domain', :to => 'sites#show', as: :site
get ':domain/releases(/p-:page)', :to => 'sites#releases', as:
:site_releases, :constraints => { :format => /(json|html)/ }
get ':domain/release/:release_id', :to => 'sites#release', as:
:site_release
end
All good so far, the routing works and the rendering works. However, when
calling the path below inside the partial "mini_release", it builds an
incorrect url:
<%= link_to site_release_path(:domain => r.site.domain, :release_id => r),
:class => 'col-xs-6' do %>
Where r is a model of Release and has one Site (which has an attribute
domain).
The URL generated is correct in terms of the URL is builds. But the
:domain section is always incorrect and is the current models object.
For example, say the page I am currently on is:
/site-one/release/my-release/ and I am rendering the partials, all the
partials result in /site-one/release/the-correct-slugs, when they should
be /some-other-site/release/the-correct-slugs. I've tried multiple formats
for the routes - with and without the variable associations - but none
work. It seems the route is taking the current route :domain parameter
instead of the given one.
How can I ensure the route stops looking at the current :domain parameter?
No comments:
Post a Comment