第0å Railsåå¼·ä¼ï¼ æ±äº¬
http://wiki.fdiary.net/rails/?Rails%CA%D9%B6%AF%B2%F1%A1%F7%C5%EC%B5%FE
å æ¥ã®11/05æ¥ã«ç¬¬0å Railsåå¼·ä¼ï¼ æ±äº¬ã«è¡ã£ã¦ãã¾ãããæ¥ãªå¿åã«ãããããã29åå ¨å¡ãæ¬ å¸ç¡ãã§åå ã¨ããããï¼
ææ³ã¯ããããªäººãæ¸ãã¦ããã®ã§ãèªåãå½æ¥çºè¡¨ããpluginã ãå ¬éãã¾ãã
http://svn.rails2u.com/public/plugins/trunk/
ActiveHeart
主ã«æ¥æ¬èªé¢ä¿ã§ä¾¿å©ãããªãã®ããªããã¨ãã£ããã®ãå ¥ã£ã¦ãpluginã§ããä»ç¾å¨ã¯
- ActiveRecordMessagesJa
- TransSid
ãå ¥ã£ã¦ã¾ããActiveRecordMessagesJaã¯ãã¾ãã¾ã¼ããã®Validationsãåèã«ã¡ãã»ã¼ã¸å¨ãã®ãã¼ã«ã©ã¤ãºãè¡ã£ã¦ã¾ãããã®pluginãå ¥ãã¦
class Foo < ActiveRecord::Base set_field_names :name, => 'ãåå', :source => 'æ¬æ'
ã¨ARã®modelå®ç¾©ã§field_nameã«å¯¾å¿ããæ¥æ¬èªãæå®ãããã¨ã§ãã»ã¼å®ç§ã«ActiveRecordã®ã¡ãã»ã¼ã¸ãæ¥æ¬èªåãããã¨ãã§ãã¾ãã
TransSidã¯phpã®äººã«ãªãã¿æ·±ãã¨æãã¾ãããsessionãcookieã§ãªãURLãªã©ã§å¼ãåãã®ã«ä½¿ãã¾ããããã¯æºå¸¯ç¨ã«çµæ§å¿
é ãªæ©è½ãªã®ã§ä½ãã¾ãããurl_forãªã©ã®railsã®URLçæã¡ã½ããã使ãã¨_session_idãèªåçã«ä»ä¸ãããã¾ãformã®hiddenã«_session_idãåãè¾¼ã¾ãã¾ããå©ç¨æ¹æ³ã¯
ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS[:trans_sid] = true
ã®ããã«ã©ããã§ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS[:trans_sid]ãtrueã«ãã¾ãããã®ã¿ã¤ãã³ã°ã¯ãã¤ã§ãOKãªã®ã§ãbefore_filterã§æºå¸¯ãã©ãããå¤å¥ãã¦ãæºå¸¯ãªãtrueã«ãã¨ãã£ã使ãæ¹ãå¯è½ã§ãã
YamlValidation
YamlValidationã¯ãã®åã®éããActiveRecordã®validationãå¤é¨yamlãã¡ã¤ã«ã«æ¸ããã¨ãã§ãã¾ããä»ã¾ã§modelå å´ã«
#app/models/foo.rb class Foo < ActiveRecord::Base validates_length_of :source , :minimum => 10 validates_length_of :password, :minimum => 8 validates_length_of :password_confirm, :minimum => 8
ã¨è¨è¿°ãã¦ããã®ã
#app/models/foo.validates.yml - validate: length_of field: source minimum: 10 - validate: length_of fields: - password - password_confirm minimum: 8
ã¨yamlã®å¥ãã¡ã¤ã«ã«ã¾ã¨ãããã¨ãå¯è½ãªããããã£ãããã¾ããvalidateãä¸ã¤ããããªãããã®ã§ãããè¤æ°ãã£ããããªãã·ã§ã³ãããããããå ´åã¯å¤é¨è¨è¿°ã§ããæ¹ã便å©ãªã®ã§ä½ãã¾ãããã§ãã½ã¼ã¹ãé常ã«æ±ãã®ã§ãRubyãã«ã¼ãªäººã¯ã¢ããã¤ã¹ããã ããã¨ããããã§ãã