How can I automatically add a subdomain to my Rails 3 route helpers

Is there a gem or a plugin that allows you to add subdomains to auxiliary route methods based on restrictions or point to .rb routes.

It would be great if something did something in this direction:

subdomain => :admin do resources :posts end admin_posts_url # => admin.url.com/posts 
+4
source share
2 answers

What you are looking for, I think, is the path to presentation

 # application_controller.rb before_filter :subdomain_view_path private def subdomain_view_path prepend_view_path "app/views/#{request.subdomain}_subdomain" if request.subdomain.present? end 

you are looking for railscasts 269 (2/3 on) for all the details

Hope this is what you are looking for.

+1
source

I have the same problem and I am able to work very well with my URL helper. Basically, I have something like this:

 def base_url "http://" + @actual_subdomain + "/" end 

And all the other helpers, I wrote a map to this. For instance:

 def category_url category base_url + category.slug end 
0
source

All Articles