serialize-rails gemã§JSONãDBã«æ ¼ç´ããã¨ããè¨äºãæ¸ãããã©ãããããgemã使ããªãã¦ã第2å¼æ°ã«æ¸¡ããªãã¸ã§ã¯ããloadã¨dumpãå®è£ ãã¦ããã°ååã ã£ããã¡ãªã¿ã«ActiveRecord 3.2ã§ç¢ºèªã ãã¨ãã°URLãURIã®ãªãã¸ã§ã¯ãã¨ãã¦æ±ãããå ´åã # app/models/uri_coder.rb class UriCoder # ActiveRecord::Baseã®ã¤ã³ã¹ã¿ã³ã¹ãä½ãããã¨ãã«å¼ã°ããã # DBããèªã¿åºããã¨ãã«ã¯stringã«ã¯ä¿åããã¦ããå¤ã渡ããã # newãããã¨ãã«ã¯nilã渡ãããã def load(string) URI.parse(string) if string.present? end # DBã«æ¸ãè¾¼ãã¨ãã«å¼ã°ããã def dump(uri) uri.to_s end end # a
Rails ã®ãã¹ããæ¸ãã¦ãã¦ããã£ã¯ã¹ãã£ã¯ã®ã¡ã®ã¡ã¡ã³ããã³ã¹ã«è¦å´ãããã ãã FactoryGirl ã使ã£ã¦ã¿ãã FactoryGirl ã«ã¤ãã¦ã¯ããã詳ãã http://www.func09.com/wordpress/archives/532 ä¸ã®ãã¼ã¸ã®ä¾ã«ããã¨ãããä¸éãã¼ãã«ã使ããããªã±ã¼ã¹ã§ãã¹ããã¼ã¿ãå®ç¾©ããã®ã«ä¾¿å©ããã (å ¬å¼ãã¼ã¸?ã§ããã®ããã«å®£ä¼ãã¦ãã) ã®ã ããä¸éãã¼ãã«ãä¸è¦ãª has_many/belongs_to ã®é¢ä¿ãå®ç¾©ããã¨ãã«ã association ã親åã©ã¡ãã«æ¸ããã§ããã£ã¦ãã¾ã£ãã ããåãããã³ã¼ãä¾ããªãã¦æ縮ã ãã©ã FactoryGirl 㧠has_many/belongs_to 㪠association ãå®ç¾©ããã¨ãã¯ãå¿ ãåã®ã»ãã«è¦ªã® Factory ãæ¸ããªãã¨ãããªãã£ã½ãããã®ã¹ã¬ã
ååã®ãã¤ã°ã¬ã¼ã·ã§ã³ããã®ç¶ãã§ãä»åã¯SinatraããActiveRecord 3ã使ã£ã¦CRUDæä½ããã¦ã¿ããã¨ãã£ã¦ããããããCRUDæä½ã«ã¤ãã¦ã¯Railsã§ä½¿ãå ´åã¨Sinatraã¨ã§ã¯ã»ã¨ãã©éãã¯ãªãã¨æããããåååæ§ãActiveRecord 3èªä½ã®ä½¿ãæ¹ã¯ãã®è¨äºãã¨ã¦ãããããããã£ãã®ã§å ¨é¢çã«åèã«ãã¦ããã ã¢ãã« ActiveRecordã使ã£ã¦DBã®CRUDæä½ãããå ´åãActiveRecord::Baseãæ´¾çããã1ã¤ã®ã¯ã©ã¹ãDBã®1ãã¼ãã«ã«å¯¾å¿ãããã®ã¯ã©ã¹ã®å±æ§ããã¼ãã«ã®åã«ã©ã ã«å¯¾å¿ãããã¨ã«ãªãããã®ã¯ã©ã¹ã®ãã¨ãä¸è¬çã«ãã¢ãã«ãã¨å¼ã¶ãRailsã§ã¯ãRailsã¢ããªãçæãã段éã§MVCå¥ã«ãã©ã«ããç¨æããã¦ããã®ã§ãmodelãã©ã«ãã«ãã®ActiveRecord::Baseæ´¾çã¯ã©ã¹ãä½ããã ãã©ãSinatraã§ã¯
以åSinatraããDataMapperã使ãè¨äºãæ¸ãããã©ãä»åã¯Sinatraã®O/Rãããã¼é¨åã«ActiveRecord 3ã使ã£ã¦ã¿ããActiveRecord 3èªä½ã®ä½¿ãæ¹ã«ã¤ãã¦ã¯ããã®è¨äºããããããããããã£ãã Sinatraã¢ããªã«å¿ è¦ãªãã¡ã¤ã«ãç¨æãã ã¾ãã¯ãSinatraã¢ããªãå®è¡ããã®ã«å¿ è¦ãªæä½éã®ãã¡ã¤ã«ç¾¤(Gemfile, config.ru, app.rb)ãä½æãããä»åã¯åºæ¬çã«ãã¹ã¦Bundlerçµç±ã§æä½ããã®ã§ãã·ã¹ãã å´ã«Bundlerã®gemãã¤ã³ã¹ãã¼ã«ããã¦ããå¿ è¦ãããã Gemfile ä»å使ç¨ããgemã¯ãããªæããã¨ããããSinatraã§ActiveRecord 3ã使ãå ´åã¯activerecordã¨sinatra-activerecordã¨sqlite3ãå¿ è¦ã§ãä»å使ã£ããã¼ã¸ã§ã³ã¯ããããã3.0.6ã0.
ãªãªã¼ã¹ãé害æ å ±ãªã©ã®ãµã¼ãã¹ã®ãç¥ãã
ææ°ã®äººæ°ã¨ã³ããªã¼ã®é ä¿¡
å¦çãå®è¡ä¸ã§ã
j次ã®ããã¯ãã¼ã¯
kåã®ããã¯ãã¼ã¯
lãã¨ã§èªã
eã³ã¡ã³ãä¸è¦§ãéã
oãã¼ã¸ãéã
{{#tags}}- {{label}}
{{/tags}}