开发者

How can I auto-prepend a subdomain to my Rails 3 route helpers

开发者 https://www.devze.com 2023-03-14 22:36 出处:网络
Is there a gem or plugin that allows you to add subdomains to your route helper methods based on constraints or by specifying in in the routes.rb.

Is there a gem or plugin that allows you to add subdomains to your route helper methods based on constraints or by specifying in in the routes.rb.

It would be awesome if there was something that would do something along these lines:

subdomain => :admin do
  resources :posts 
end

admin_posts_url # => a开发者_Python百科dmin.url.com/posts


What you're looking for I think is prepend view path

# 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 for all the details have a look at railscasts 269 (2/3 on)

I hope this is what you're looking for.


I have the same issue and I manage to get my own url helper working pretty well. Basically, I have something like this :

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

And every others helper taht I wrote map to this one. Like ;

def category_url category
    base_url + category.slug
end
0

精彩评论

暂无评论...
验证码 换一张
取 消