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
# These are the sizes of the domain (i.e. 0 for localhost, 1 for something.com)
# for each of your environments
SubdomainFu.tld_sizes = { :development => 0,
:test => 0,
:production => 1 }
# These are the subdomains that will be equivalent to no subdomain
SubdomainFu.mirrors = ["www"]
# This is the "preferred mirror" if you would rather show this subdomain
# in the URL than no subdomain at all.
SubdomainFu.preferred_mirror = "www"
# http://some_subdomain.myapp.com/
current_subdomain # => "some_subdomain"
# http://www.myapp.com/ or http://myapp.com/
current_subdomain # => nil
# http://some.subdomain.myapp.com
current_subdomain # => "some.subdomain"
url_for(:controller => "my_controller",
:action => "my_action",
:subdomain => "awesome") # => http://awesome.intridea.com/my_controller/my_action
users_url(:subdomain => false) # => http://intridea.com/users
# The full URL will be generated if the subdomain is not the same as the
# current subdomain, regardless of whether _path or _url is used.
users_path(:subdomain => "fun") # => http://fun.intridea.com/users
users_path(:subdomain => false) # => /users
Implementing A Simple Account Key System
class ApplicationController < ActionController::Base
protected
# Will either fetch the current account or return nil if none is found
def current_account
@account ||= Account.find_by_subdomain(current_subdomain)
end
# Make this method visible to views as well
helper_method :current_account
# This is a before_filter we'll use in other controllers
def account_required
unless current_account
flash[:error] = "Could not find the account '#{current_subdomain}'"
redirect_to :controller => "site", :action => "home", :subdomain => false
end
end
end
沒有留言:
張貼留言
較新的文章
較舊的文章
首頁
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言