C
C
Ceyoto2015-03-31 14:48:06
Ruby on Rails
Ceyoto, 2015-03-31 14:48:06

How to make a redirect from a 3rd level domain to a 2nd one when selecting a tag?

I use gem 'acts-as-taggable-on' for tags.
On the main page, the tags have the address simple.com/tag/:tag, as I understand it, /tag/:tag is substituted for the root of the site.
When I go to the record of the selected tag, I get to the 3rd level domain test.simple.com.
On the same page, I try to select another tag, but it is already substituted with the address test.simple.com/tag/:tag, respectively, to the root of the site.
How can I make the tag address simple.com/tag/:tag when selecting a tag on the 3rd level domain?
View - display tags

- tag_cloud Model.tags.tag_counts, %w[css] do |tag, css_class|
  = active_link_to tag.name, tag_path(tag.name), class: css_class, active: :exclusive

Here active: :exclusive is the 'active' class substitution for the selected entry from the active_link_to gem. Here, as I understand it, it won’t work at all if there is a 3rd-level domain. Since being on a subdomain, the tag address will be different from the current page.
I do subdomains as described in this article
routes.rb
get 'tag/:tag', to: 'home#index', as: :tag

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
Ceyoto, 2015-03-31
@Ceyoto

I did this, but something tells me that there are better ways

unless request.subdomain.blank?
  tag_path_url = tag_path.gsub!('/tag', 'tag') - здесь потому что при редиректе он добавляет два слеша перед 'tag'
  root = root_url(subdomain: false) + tag_path_url
  redirect_to root
end

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question