ããã²ãèªè¨¼ãã©ã°ã¤ã³(acts_as_yukihiro_ninshoable)
Rubyä¼è°2007ããã¨ããRejectä¼è°2007ã§çºè¡¨ãããベーパーウェアのアイデアã«æéãåããããããã¾ããã«å®è£ ãã¦ãã¾ãã¾ãããåçã¯ãã¦ããªãã
ãã®Railsãã©ã°ã¤ã³ãã¤ã³ã¹ãã¼ã«ããã¨ç´ 人ãã¾ã¤ãã¨ããã²ãããã®ååããããã²ããããã¨ééãããã¨ãå©ç¨ãã¦ã¦ã¼ã¶ã¼ãèªè¨¼ã§ããããã«ãªãã¾ããã¾ãèªè¨¼å¤±æãã¦ãããä¸åº¦èãããã ããªã®ã§ãæ大äºåã§ç¢ºå®ã«ãã°ã¤ã³ã§ãã¾ããã©ãããªãã«ä½¿ããã ï¼ãã¨ããããããã¨ã¯èãã¡ãé§ç®ã
ã¤ã³ã¹ãã¼ã«
1. ä¸è¨ã³ãã³ããå®è¡ãã¦ããã²ãèªè¨¼ãã©ã°ã¤ã³ãã¤ã³ã¹ãã¼ã«ãã
./script/plugin install svn://rubyforge.org/var/svn/yukihiro-ninsho/vendor/plugins/yukihiro_ninsho
2. ã³ã³ããã¼ã©ã¼ã§ãããªæãã«å®£è¨ãã
class ApplicationController < ActionController::Base acts_as_yukihiro_ninshoable
3. èªè¨¼ããã¦ãªãç¶æ ã§ãã¼ã¸ã表示ãããã¨ãã¦ãããªãã¨æå
ã½ã¼ã¹ã³ã¼ã
ã½ã¼ã¹ãTxDã«ä¸ãã¦ã¿ããã ãã©ããªãã ãã¯ã½éãä¸ã«ããè½ã¡ãã®ã§RubyForgeã«ç³è«ä¸ãå¾
ã¡ãããªãå ´åã¯èªåã§ä½ã£ã¦ã¿ãã¨ããã¨æããã
å¿
è¦ãªãã¡ã¤ã«ã¯ãã£ãäºã¤ã ãã
ï¼RubyForgeã«ç»é²ãããã©ãä¸å¿ã³ã¼ãã¯æ®ãã¦ããã¾ãï¼
# vendor/plugins/yukihiro_ninsho/init.rb require 'yukihiro_ninsho'
# vendor/plugins/yukihiro_ninsho/lib/yukihiro_ninsho.rb class ActionController::Base def self.acts_as_yukihiro_ninsho(*args) define_method :yukihiro_check do if params[:action] == 'yukihiro_login' yukihiro_login elsif params[:action] == 'yukihiro_check' yukihiro_render_check elsif session[:i_love_ruby] == :ofcourse true else yukihiro_render_check end end define_method :yukihiro_render_check do params[:action] = 'yukihiro_welcome' if params[:action] == 'yukihiro_login' params[:only_path] = false render :inline => <<-end_of_template <% form_tag :action => 'yukihiro_login', :from => url_for(params) do %> <h4>Rubyãéçºããã®ã¯æ¬¡ã®ãã¡ã©ã¡ãï¼</h4> <%= select_tag :matz, options_for_select( [['ã¾ã¤ãã¨ããã²ã', 'yukihiro'], ['ã¾ã¤ãã¨ã²ããã', 'hiroyuki']]), :size => 2, :style => 'border:1px solid gray' %> <br/> <%= submit_tag 'ãã°ã¤ã³' %> <% end %> end_of_template false end define_method :yukihiro_login do if params[:matz] == 'yukihiro' session[:i_love_ruby] = :ofcourse redirect_to params[:from] and return false else yukihiro_render_check end end define_method :yukihiro_logout do session[:i_love_ruby] = nil redirect_to :action => 'yuhikiro_check' end define_method :yukihiro_welcome do render :inline => <<-end_of_template <h4>ç¡äºã«èªè¨¼ããã¾ãã</h4> <%= link_to 'ãã°ã¢ã¦ã', :action => 'yukihiro_logout' %> end_of_template end before_filter *(args.unshift(:yukihiro_check)) end end
⻠注æ
ã¾ã¨ããªãã¹ãã¯ãã¦ã¾ããããå©ç¨ã¯èªå·±è²¬ä»»ã§ãã£ã¦ãããããã¿ä»¥å¤ã®ãªã«ãã®ã§ããªãã®ã§ãï¼ãããªäººããªãã¨æããã©ï¼ããã§ä½ããèªè¨¼ã§ããããããã¨ã¯æå¾ ããªãã§ãã ããã
â» ããã«æ³¨æ
ãããã²ãèªè¨¼ãã§ã°ã°ã£ã¦æ¥ã人ããããããhttp://www.coins.tsukuba.ac.jp/~i021179/blog/20070613ããRejectä¼è°ã§ã®å ãã¿ãªã®ã§æ³¨æãã¦ãã ããã
before_filterå ã§ã®renderã¨redirect_to
before_filterå ã§ã¨ã©ã¼ã¡ãã»ã¼ã¸ãrenderãããã¨ã©ã¼ãã¼ã¸ã«ãªãã¤ã¬ã¯ãããå ´åã¯åæã«return falseããå¿ è¦ãããã¾ããããããªãã¨ã以éã®ãã£ã«ã¿ãå®è¡ããã¦æç»ã2度以ä¸è¡ãããã¨ããã¨ã©ã¼ã«ãªãã¾ãã
ããã²ãèªè¨¼ã®ä¾ã§è¨ãã°ãã®é¨åã
define_method :yukihiro_login do if params[:matz] == 'yukihiro' session[:i_love_ruby] = :ofcourse redirect_to params[:from] and return false # âãã®ãand return falseã else yukihiro_render_check end end
ã¦ããããRailsã¯ãããªãã¨ã¾ã§ã¨ã©ã¼ã¡ãã»ã¼ã¸ã§æãã¦ããããããããã°ãããã
ã¯ã©ã¹ã¡ã½ããã®å¥å
ãã¼ããªãããã£ã¨ããã®ãªãã®ããªã¼
class Hoge def self.fizz; puts :fizz end class <<self; alias buzz fizz end end Hoge.buzz
æè¤ãã
Rejectä¼è°ã®ããã²ãèªè¨¼ã¯å人çã«é常ã«ããã£ãã®ã§ä»æ¥ä¸ã«3-4åãããã¯å®è£ åºã¦ããããªã¼ã¨æã£ã¦ããã ãã©ãããããåºã¦ããªãã®ãªãã¨ãããããã®çºè¡¨è ã«é¢ããæ å ±ã®å°ãªãã¯ç°å¸¸ã公式サイトã§ãã
ãããã²ãã(not ã²ããã) èªè¨¼
æè¤
ã£ã¦ãååã ãããããã¦ãããèåã ããããããªã³ã¯ããªãããæ¥æ¬ã«ä½äººæè¤ãããããã¨æã£ã¦ãã *1ã
ãã®ã¾ã¾è¬ã®æè¤ããã§çµãã£ããå人çä¼èª¬ã®ãªãã³ã ãªãã
[追è¨]
公式サイトã®æ
å ±ãæ´æ°ããã¦ã¾ããã
è¿æ¥å
¬éãã°ã°ãããã»ã»ã»ã
ã¯ã¦ãªã®SEOãã¯ã¼ã®ããã§ã°ã°ãã¨ããã«æ¥ã¡ããããã»ã»ã»ã
*1:日本で10番目に多い苗字ããã