2008年10月16日 星期四

javascript, scope, function


<script type="text/javascript">
var global_function = null; <= 宣告在這裡才是global的
(function($){
function local_funtion() { <= 這裡只是 local的
}
global_funcion = function() { <= 指定變數 成function
}
})(jQuery);
</script>
<script type="text/javascript">
global_function(); <= global這裡才叫的到
</script>

2008年10月15日 星期三

substring, substr,js

String.substr(N1,N2) :從指定的位置(N1)截取指定長度(N2)的字串。
String.substring(N1,N2) :從指定的位置(N1)到指定的位置(N2)的字串。

request methods

http://api.rubyonrails.org/classes/ActionController/AbstractRequest.html#M000802

How to limit users to one vote per IP address

http://railsauthority.com/tutorial/how-to-limit-users-to-one-vote-per-ip-address
http://railsauthority.com/tutorial/how-to-obtain-the-ip-address-of-the-current-user
http://ithelp.ithome.com.tw/question/10011184

  1. # 以 regular expression 的設法來指定可執行的 IP 或範圍
  2. unless request.env['HTTP_X_REAL_IP'] =~ /^192\.168\.1\.(101|204|77|9)$|^168\.95\.1\./
  3. render :text => '不准看!'
  4. end

2008年10月12日 星期日

layout, select_layout


layout :select_layout

def select_layout
case action_name
when 'action1', 'action2'
'layout1'
when 'action3'
'layout2'
end
end

image_tag, path, url


http://api.rubyonrails.com/classes/ActionView/Helpers/AssetTagHelper.html


ActionController::Base.asset_host = "assets.example.com"
image_tag("rails.png")
=> <img src="http://assets.example.com/images/rails.png" alt="Rails" />
stylesheet_link_tag("application")
=> <link href="http://assets.example.com/stylesheets/application.css" media="screen" rel="stylesheet" type="text/css" />



ActionController::Base.asset_host = Proc.new { |source| "http://assets#{rand(2) + 1}.example.com" }
image_tag("rails.png")
=> <img src="http://assets2.example.com/images/rails.png" alt="Rails" />
stylesheet_link_tag("application")
=> <link href="http://assets1.example.com/stylesheets/application.css" media="screen" rel="stylesheet" type="text/css" />



ActionController::Base.asset_host = Proc.new { |source|
if source.starts_with?('/images')
"http://images.example.com"
else
"http://assets.example.com"
end
}
image_tag("rails.png")
=> <img src="http://images.example.com/images/rails.png" alt="Rails" />
stylesheet_link_tag("application")
=> <link href="http://assets.example.com/stylesheets/application.css" media="screen" rel="stylesheet" type="text/css" />



ActionController::Base.asset_host = Proc.new { |source, request|
if request.ssl?
"#{request.protocol}#{request.host_with_port}"
else
"#{request.protocol}assets.example.com"
end
}

2008年10月4日 星期六

ㄎㄎ