ubuntu, ror, jQuery, css, website memo
太嫩, 沒啥心得, 用來紀錄每天學的
2009年9月1日 星期二
subdomain-fu, subdomain
Railscast Subdomains-Fu
SubdomainFu: A New Way To Tame The Subdomain
Don't Forget To Reserve Subdomains For Yourself
# in environment.rb<br /> <br /># These are the sizes of the domain (i.e. 0 for localhost, 1 for something.com)<br /># for each of your environments<br />SubdomainFu.tld_sizes = { :development => 0,<br /> :test => 0,<br /> :production => 1 }<br /><br /># These are the subdomains that will be equivalent to no subdomain<br />SubdomainFu.mirrors = ["www"]<br /><br /># This is the "preferred mirror" if you would rather show this subdomain<br /># in the URL than no subdomain at all.<br />SubdomainFu.preferred_mirror = "www"<br />
<br /># http://some_subdomain.myapp.com/<br />current_subdomain # => "some_subdomain"<br /><br /># http://www.myapp.com/ or http://myapp.com/<br />current_subdomain # => nil<br /><br /># http://some.subdomain.myapp.com<br />current_subdomain # => "some.subdomain"<br />
<br />url_for(:controller => "my_controller", <br /> :action => "my_action", <br /> :subdomain => "awesome") # => http://awesome.intridea.com/my_controller/my_action<br /> <br />users_url(:subdomain => false) # => http://intridea.com/users<br /><br /># The full URL will be generated if the subdomain is not the same as the<br /># current subdomain, regardless of whether _path or _url is used.<br />users_path(:subdomain => "fun") # => http://fun.intridea.com/users<br />users_path(:subdomain => false) # => /users<br />
Implementing A Simple Account Key System
<br />class ApplicationController < ActionController::Base<br /> protected<br /> <br /> # Will either fetch the current account or return nil if none is found<br /> def current_account<br /> @account ||= Account.find_by_subdomain(current_subdomain)<br /> end<br /> # Make this method visible to views as well<br /> helper_method :current_account<br /> <br /> # This is a before_filter we'll use in other controllers<br /> def account_required<br /> unless current_account<br /> flash[:error] = "Could not find the account '#{current_subdomain}'"<br /> redirect_to :controller => "site", :action => "home", :subdomain => false<br /> end<br /> end<br />end<br />
沒有留言:
張貼留言
較新的文章
較舊的文章
首頁
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言