ç§ãç¥ç€Ÿã®éçºãå§ããŠãã1幎以äžãçµã¡ãŸããã ãã®éãShrineã¯å€ãã®èå³æ·±ãæ©èœãåãåãããšã³ã·ã¹ãã ãå€§å¹ ã«æé·ããååãªéçºè ãæ¬çªç°å¢ã§Shrineã䜿çšãå§ããŸããã
å©ç¹ã®èª¬æãæãäžããåã«ãäžæ©æ»ã£ãŠãäž»ã«ç¥ç€Ÿã®éçºã®åæ©ãšããŠäœã圹ç«ã£ããã詳现ã«æ€èšããå¿ èŠããããŸãã
ç¹ã«ãæ¢åã®ããŒãããŒããŒã®å¶éã«ã€ããŠã話ããããšæããŸãã ããŒãºã«æé©ãªéžæãè¡ããããã«ããããã®å¶éãèªèããããšãéèŠã ãšæããŸã ã
å¿ èŠæ¡ä»¶
èŠä»¶ã¯æ¬¡ã®ãšããã§ãã
- Amazon S3äžã®ãã¡ã€ã«ã¯çŽæ¥ããŠã³ããŒãããå¿ èŠããããŸã
- ãã¡ã€ã«ã¯ããã¯ã°ã©ãŠã³ãã§åŠçããã³åé€ããå¿ èŠããããŸãã
- ããŠã³ããŒãåŠçäžã«åŠçãå®è¡ãããå ŽåããããŸãã
- ç¶ç·šã®çµ±å
- Rails以å€ã®ãã¬ãŒã ã¯ãŒã¯ã§äœ¿çšããæ©èœ
ç§ã®æèŠã§ã¯ãæåã®2ã€ã®ãã€ã³ãã¯éåžžã«éèŠã§ãããã©ãŒã ãæäœãããšãã«æé©ãªãŠãŒã¶ãŒã€ã³ã¿ãŒãã§ã€ã¹ãå®çŸã§ããããã§ãã ãã ããæåŸã®2ç¹ã泚æããã«æŸçœ®ããªãã§ãã ããã
1. Amazon S3ãŸãã¯é¡äŒŒç©ã䜿çšããŠããã¡ã€ã«ã®ããŠã³ããŒãããã»ã¹ãæé©åã§ããŸãã
ããã«ã¯ç¢ºãã«ããã€ãã®å©ç¹ããããŸãããªãœãŒã¹æ¶è²»ã®åæžãã¹ãã¬ãŒãžã«ãã»ã«åã«ããæ°Žå¹³ã¹ã±ãŒãªã³ã°ãHerokuãªã©ã®ãã£ã¹ã¯ããŒã¹ã®ãœãªã¥ãŒã·ã§ã³ãšã®é£æºã ãã£ã¹ã¯æžã蟌ã¿æ©èœãæäŸããã ã¯ãšãªå®è¡ã«æéå¶éããããŸã ã
2.ããã¯ã°ã©ãŠã³ãã¿ã¹ã¯ã§ã®ãã¡ã€ã«ã®åŠçãšåé€ã«ãããããŒã«ã«ãã¡ã€ã«ã·ã¹ãã ãŸãã¯Amazon S3ãªã©ã®å€éšã¹ãã¬ãŒãžã«ãã¡ã€ã«ãä¿åãããã©ããã«é¢ä¿ãªãããã¡ã€ã«ãéåæã§æäœã§ããŸããããã«ããããŠãŒã¶ãŒã€ã³ã¿ãŒãã§ã€ã¹ãå€§å¹ ã«æ¹åãããŸãã ããã¯ã°ã©ãŠã³ãã¿ã¹ã¯ã䜿çšããããšããã¢ããªã±ãŒã·ã§ã³ã®é«åž¯åå¹ ãç¶æããããã«å¿ èŠã§ããããã¯ãã¯ãŒã«ãŒãé ãèŠæ±ã«çžãããªãããã§ãã
3.ããŠã³ããŒãããã»ã¹äžã®åŠçã¯ãç¹ã«ãã¡ã€ã«ã®ãµã€ãºãç°ãªããªã©ãè€æ°ã®ãã¡ã€ã«ããŒãžã§ã³ãäœæãããå Žåã¯ç¹ã«ãå°ããªãã¡ã€ã«ã§æ£åžžã«æ©èœããŸãã äžæ¹ãããŠã³ããŒãåŠçã¯ããããªãªã©ã®å€§ããªãã¡ã€ã«ã«ãå¿ èŠã§ãã ãã®ãããããããçš®é¡ã®ãã¡ã€ã«ãåŠçã§ããã©ã€ãã©ãªãå¿ èŠã§ãã
4. ActiveRecord以å€ã®ORMã§äœ¿çšããããšãéåžžã«éèŠã§ãã ãã§ã«ç»å Žããããã«ãããæ©èœçã§çç£çãªRubyã®ORMã
5.æåŸã«ãRailsã«ãµãããã代æ¿ç©ãRubyã³ãã¥ããã£ã«ç»å ŽããŸããã Webãã¬ãŒã ã¯ãŒã¯ãšç°¡åã«çµ±åããæ©èœãå¿ èŠã§ãã
次ã«ãèŠä»¶ãèæ ®ããŠãæ¢åã®ã©ã€ãã©ãªã調ã¹ãŠããããã®äž»ãªæ¬ ç¹ãæ€èšããŸãã
ã¯ãªãã
ActiveRecordã®ç°¡åãªæ·»ä»ãã¡ã€ã«ç®¡ç
ActiveRecordã«åŒ·ãäŸåããŠãããããåæ»-ããããªãPaperclipãšèšããŸãã ããã¯ActiveRecordã§äœ¿çšãããéåžžã«äžè¬çãªã©ã€ãã©ãªãªã®ã§ãæ®ãã®èŠä»¶ãèŠãŠãããŸãããã
çŽæ¥ããŠã³ããŒã
Paperclipã«ã¯çŽæ¥ããŠã³ããŒãæ©èœã¯ãããŸããã aws-sdkã䜿çšããŠãS3ã«çŽæ¥èªã¿èŸŒãããã®ãªã³ã¯ãšãã©ã¡ãŒã¿ãŒãçæããPaperclipãä»ããŠãã¡ã€ã«ãããŠã³ããŒããããšããšåãæ¹æ³ã§ã¢ãã«å±æ§ãç·šéã§ããŸãã
ãã ããPaperclipã¯1ã€ã®ãªããžããªã§ã®ã¿æ©èœããŸãã åäœããã«ã¯ããã¹ãŠã®ããŠã³ããŒããã¡ã€ã³ã®S3ã¹ãã¬ãŒãžã§çŽæ¥è¡ãããå¿ èŠããããŸãã æ»æè ã¯æ·»ä»ãã¡ã€ã«ãªãã§ãã¡ã€ã«ãã¢ããããŒãã§ãããã®çµæãå€ãã®å€ç«ãããã¡ã€ã«ãäœæãããå¯èœæ§ããããããããã¯ã»ãã¥ãªãã£ã®åé¡ã«ã€ãªãããŸãã S3ããããããªãã®ããã«ãããªããããã¯ã¯ããã«ç°¡åã§ãããã
ããã¯ã°ã©ãŠã³ãã¿ã¹ã¯
ããã¯ã°ã©ãŠã³ãã¿ã¹ã¯ã§ã¯ã delayed_paââpeclipã䜿çšãããŸãã ãã ããdelayed_paââperclipã¯ããã¡ã€ã«ãå®å šã«ããŠã³ããŒããããåŸã«ã®ã¿ã¿ã¹ã¯ãéå§ããŸãã ã€ãŸããS3ãžã®çŽæ¥ããŠã³ããŒããæãŸãªãå ŽåããŸãã¯ã§ããªãå ŽåããŠãŒã¶ãŒã¯ããã¯ã°ã©ãŠã³ãåŠçãè¡ãåã«ãã¡ã€ã«ã2åïŒæåã«ã¢ããªã±ãŒã·ã§ã³ã次ã«ã¹ãã¬ãŒãžã«ïŒããŠã³ããŒãããå¿ èŠããããŸãã ãããŠãããã¯éåžžã«é ãã§ãã
ãŸããdelayed_paââperclipã¯ãããã¯ã°ã©ãŠã³ãã§ã®ãã¡ã€ã«ã®åé€ããµããŒãããŠããŸããã ããã¯å€§ããªãã€ãã¹ã§ãããã¡ã€ã«ã®åããŒãžã§ã³ã«å¯ŸããŠHTTPãªã¯ãšã¹ããå®è¡ããå¿ èŠãããããã§ãïŒS3ã«è€æ°ã®ããŒãžã§ã³ã®ãã¡ã€ã«ãä¿åãããŠããå ŽåïŒã Paperclipã¯ãã¢ã³ã€ã³ã¹ããŒã«ããåã«åããŒãžã§ã³ã®ååšããã§ãã¯ããããããã®æ©èœãè¿œå ãããããšãæåŸ ããªãã§ãã ããã ãã¡ããããã¡ã€ã«ã®åé€ãç¡å¹ã«ããããšã¯ã§ããŸããããããããšå€ç«ãã¡ã€ã«ã«åé¡ãçããŸãã
æåŸã«ã delayed_paââperclipã¯ActiveJobã«ãã€ã³ããããããã«ãªããŸãããã€ãŸããããã¯ã°ã©ãŠã³ãã¿ã¹ã¯ã®ã©ã€ãã©ãªã§çŽæ¥äœ¿çšããããšã¯ã§ããªããªããŸããã
ãªãããŸãæ»æã®MIMEã¿ã€ãã®èª€æ€åº
Paperclipã«ã¯ã誰ãããã¡ã€ã«ã®MIMEã¿ã€ãã眮ãæããããšããŠãããã©ãããæ€åºããæ©èœããããŸãã ãã ãããã®æ©èœã¯ãã°ãã°èª€ã£ãŠæ©èœãããã¡ã€ã«æ¡åŒµåããã¡ã€ã«ã®å 容ãšäžèŽããŠããæ€èšŒãšã©ãŒãçºçããå¯èœæ§ããããŸãã ãã®å Žåã誀æ€ç¥ã¯ãŠãŒã¶ãŒã«ãšã£ãŠéåžžã«è¿·æãªãããããã¯éåžžã«æ±ºå®çãªèŠå ã§ãã
ãã¡ããããã®æ©èœãç¡å¹ã«ããããšãã§ããŸãããããã«ããã¢ããªã±ãŒã·ã§ã³ã¯ãã¡ã€ã«ãããŠã³ããŒãããéã®æ»æã«å¯ŸããŠè匱ã«ãªããŸã ã
æ¬éæ³¢
RailsãSinatraããã®ä»ã®Webãã¬ãŒã ã¯ãŒã¯åãã®åªãããã¡ã€ã«ã¢ããããŒããœãªã¥ãŒã·ã§ã³
CarrierWaveã¯ãã¯ã©ã¹å ã«ã«ãã»ã«åããŠãã¢ãã«å ã®æ§æãæ£ããç¶æããPaperclipãžã®çãã§ãã
CarrierWaveã¯Sequelãšçµ±åãããŠããŸãã
æ®å¿µãªããã carrierwave_backgrounderããã³carrierwave_directæ¡åŒµæ©èœã®å ŽåãORM CarrierWaveçµ±åã§ã¯ååã§ã¯ãããŸããã åäœãããã«ã¯ãActiveRecordåºæã®è¿œå ã³ãŒããããããå¿ èŠã§ãã
çŽæ¥ããŠã³ããŒã
åè¿°ã®ããã«ãCarrierWaveãšã³ã·ã¹ãã ã«ã¯S3- carrierwave_directã«çŽæ¥èªã¿èŸŒã¿ãœãªã¥ãŒã·ã§ã³ããããŸãã ããã¯ãS3ã«çŽæ¥ã¢ããããŒãããããã®ãã©ãŒã ãäœæããããŠã³ããŒããããã¡ã€ã«ã®S3ããŒãããŒãããŒããŒã«å²ãåœãŠãããšãã§ããããã«æ©èœããŸãã
<!-- Form submits to "https://my-bucket.s3-eu-west-1.amazonaws.com" --> <%= direct_upload_form_for @photo.image do |f| %> <%= f.file_field :image %> <%= f.submit %> <% end %>
ãã ããS3ã«çŽæ¥è€æ°ã®ããŠã³ããŒããè¡ãå¿ èŠãããå Žåã¯ã©ããªããŸããïŒ READMEã¯ãcarrierwave_directãã·ã³ã°ã«ããŠã³ããŒãå°çšã§ããããšãææããŠããŸãã JSON APIã¯ã©ãã§ããïŒ ããã¯éåžžã®åœ¢åŒã§ãããS3ã«ã¢ããããŒãããããã®URLãšãã©ã¡ãŒã¿ãŒãçæããã ããªã®ã§ãcarrierwave_directããã®æ å ±ãJSON圢åŒã§ååŸããªãã®ã¯ãªãã§ããïŒ
ãããã fog-awsã䜿çšããŠS3ãªã¯ãšã¹ãçæããžãã¯å šäœãåå®è£ ãã代ããã«ãåã«aws-sdkã«äŸåããŠããå Žåã¯ã©ãã§ããããïŒ
# aws-sdk bucket = s3.bucket("my-bucket") object = bucket.object(SecureRandom.hex) presign = object.presigned_post
<!-- HTML version --> <form action="<%= presign.url %>" method="post" enctype="multipart/form-data"> <input type="file" name="file"> <% presign.fields.each do |name, value| %> <input type="hidden" name="<%= name %>" value="<%= value %>"> <% end %> <input type="submit" value="Upload"> </form>
# JSON version { "url": presign.url, "fields": presign.fields }
ãã®ã¡ãœããã«ã¯æ¬¡ã®å©ç¹ããããŸãïŒRailsã«é¢é£ä»ããããŠããããJSON APIã§åäœããè€æ°ã®ãã¡ã€ã«ã®ããŠã³ããŒãããµããŒãããŸãïŒã¯ã©ã€ã¢ã³ãã¯åãã¡ã€ã«ã«å¯ŸããŠãã®ããŒã¿ã䜿çšããŠåçŽã«ãªã¯ãšã¹ããè¡ãããšãã§ããŸãïŒã ïŒ
ããã¯ã°ã©ãŠã³ãã¿ã¹ã¯
ãŸããcarrierwave_directãããã¯ã°ã©ãŠã³ãåŠçãèšå®ããããã®æ瀺ãæäŸããããšã«æ³šæããŠãã ããã ãã ããããã¯ã°ã©ãŠã³ãã¿ã¹ã¯ãæ£ããèšå®ããã®ã¯ããªãé£ããã¿ã¹ã¯ãªã®ã§ããããè¡ãã©ã€ãã©ãªã«äŸåããã®ã¯çã«ããªã£ãŠããŸãã
ããã¯ã carrierwave_backgrounderã«ã€ãªãããŸãã ãã®ã©ã€ãã©ãªã¯ããã¯ã°ã©ãŠã³ãã¿ã¹ã¯åŠçããµããŒãããŠããŸãããç§ã®çµéšã§ã¯äžå®å®ã§ããïŒ 1ããã³2 ïŒã ãŸããããã¯ã°ã©ãŠã³ãã§ãã¡ã€ã«ãåé€ããããšããµããŒãããŠããŸãããããã¯ãè€æ°ã®ãã¡ã€ã«ãåé€ããéã®æ±ºå®çãªèŠå ã§ãã
ããããã¹ãŠå æãããšããŠããcarrierwave_backgrounderãšcarrierwave_directãçµ±åããããšã¯ã§ããŸããã åè¿°ããããã«ããã¡ã€ã«ãS3ã«çŽæ¥ã¢ããããŒãããããã¯ã°ã©ãŠã³ãã¿ã¹ã¯ã§ãã¡ã€ã«ãåŠçããã³åé€ããããšæããŸãã ãããããããã®2ã€ã®ã©ã€ãã©ãªã¯çžäºã«äºææ§ããªãããã§ããããã¯ãç§ã®å ŽåãCarrierWaveã§ç®çã®ããã©ãŒãã³ã¹ãéæã§ããªãããšãæå³ããŸãã
Githubã§æªè§£æ±ºã®åé¡ãéãã
人æ°ã®ãããªãŒãã³ãœãŒã¹ã©ã€ãã©ãªã®ã¡ã³ãããŒã«æè¬ããªã人ãããããšãç解ããŠããããäºããããæãããå°éãã䟡å€ããããŸãã ãã ã ã CarrierWave éçºè ã æªè§£æ±ºã® ã¿ã¹ã¯ã éãã çç±ã ç解 ã§ããŸãã ã
ãã®ãããªéããããã¿ã¹ã¯ã®1ã€ã¯ãæ€èšŒã®åã«CarrierWaveåŠçãäžå¿ èŠã«å®è¡ããããšã§ãã ããã¯æ·±å»ãªã»ãã¥ãªãã£ããŒã«ã§ãããã¡ã€ã«ãµã€ãº/ MIME /枬å®å€ã®æ€èšŒã¯åŠçåŸã«ã®ã¿å®è¡ããããããæ»æè ã¯ä»»æã®ãã¡ã€ã«ãç»åããã»ããµã«è»¢éã§ããããã§ãã ããã«ãããã¢ããªã±ãŒã·ã§ã³ã¯ImageTragick ã ç»åç匟ããŸãã¯å€§ããªç»åã®ããŠã³ããŒããªã©ã®æ»æã«å¯ŸããŠè匱ã«ãªããŸãã
æŽé
Rubyãžã®ãã¡ã€ã«ã®ã¢ããããŒããè©Šè¡3
Refileã¯ãCarrierWaveã®äœè ã§ããJonas Niklasã«ãã£ãŠãRubyã§ã®ãã¡ã€ã«ã¢ããããŒããæ¹åãã3çªç®ã®è©Šã¿ãšããŠäœæãããŸãããDragonflyãšåæ§ã«ãRefileã¯ãªã³ã¶ãã©ã€ã§åŠçã§ããããã«èšèšãããŸããã CarrierWaveã®è€éãã«æ©ãŸãããåŸãRefileã®ã·ã³ãã«ã§ã¢ãã³ãªãã¶ã€ã³ãæ¬åœã«ææã§ããããšãããã£ãã®ã§ãç§ã¯ããã«è²¢ç®ãå§ããæçµçã«ç§ã¯ããã«æåŸ ãããŸããã
Refile.attachment_url(@photo, :image, :fit, 400, 500) # resize to 400x500 #=> "/attachments/15058dc712/store/fit/400/500/ed3153b9cb"
Refileã®æ°ããã¢ã€ãã¢ã«ã¯ãäžæ¬¡ã¹ãã¬ãŒãžãšããŠã®äžæçããã³æ°žç¶çã¹ãã¬ãŒãžãã¹ãã¬ãŒãžã®ã¯ãªãŒã³ãªæœè±¡åãIOæœè±¡åãã¯ãªãŒã³ãªå éšãã¶ã€ã³ïŒGODãªããžã§ã¯ããªãïŒãããã¯ã¹ããã®çŽæ¥ããŠã³ããŒããå«ãŸããŸãã ããããªRefileãã¶ã€ã³ã®ãããã§ãSequelçµ±åã®äœæã¯éåžžã«ç°¡åã§ããã
çŽæ¥ããŠã³ããŒã
Refileã¯ããã¡ã€ã«ãããŠã³ããŒãããæåã®ã©ã€ãã©ãªã§ããçŽæ¥ããŠã³ããŒãã®ãµããŒããçµã¿èŸŒãŸããŠããããããŠãŒã¶ãŒãéžæãããšãã«æ·»ä»ãã¡ã€ã«ãéåæã§ããŠã³ããŒãã§ããŸãã ã©ãã¯çµç±ã§ãã¡ã€ã«ãã¢ããããŒãããããRefileã䜿çšããŠS3ã«çŽæ¥ã¢ããããŒãããŠãS3èŠæ±ãã©ã¡ãŒã¿ãŒãçæã§ããŸãã ãã¹ãŠãè¡ãJavaScriptã©ã€ãã©ãªããããŸãã
<%= form.attachment_field :image, presigned: true %>
ãŸããããã©ãŒãã³ã¹ãå€§å¹ ã«åäžããŸãã ãã¡ã€ã«ãS3ã«çŽæ¥ã¢ããããŒãããå ŽåããäžæããšããŠããŒã¯ãããŠãããã±ãããã£ã¬ã¯ããªã«ã¢ããããŒãããŸãã 次ã«ãæ€èšŒã«åæ Œããã¬ã³ãŒããä¿åããããšãããŠã³ããŒããããã¡ã€ã«ã¯æ°žç¶çãªã¹ãã¬ãŒãžã«ç§»åãããŸãã äžæã¹ãã¬ãŒãžãšæ°žç¶ã¹ãã¬ãŒãžãS3ã«ããå ŽåãRefileããªããŒããã代ããã«ãS3 COPYèŠæ±ãçºè¡ããŸãã
èšèã§ã¯ãªããçŽæ¥ããŠã³ããŒãã®èŠä»¶ãæºãããŸããã
ããã¯ã°ã©ãŠã³ãã¿ã¹ã¯
Refileã®å¶éã®1ã€ã¯ãããã¯ã°ã©ãŠã³ããžã§ãã®ãµããŒãã®æ¬ åŠã§ãã Refileã¯ããŒãæã«åŠçãå®è¡ããS3 COPYã®æé©åããããããããã§ã¯ããã¯ã°ã©ãŠã³ãã¿ã¹ã¯ã¯äžèŠã ãšæããããããããŸããã
ãã ããS3 COPYèŠæ±ã¯HTTPèŠæ±ã®ãŸãŸã§ããããã©ãŒã éä¿¡ã®æéã«åœ±é¿ããŸãã ããã«ãS3 COPYèŠæ±ã®é床ã¯ãã¡ã€ã«ãµã€ãºã«äŸåããããããã¡ã€ã«ã倧ããã»ã©ãS3 COPYèŠæ±ã¯é ããªããŸãã
ããã«ãAmazon S3ã¯å€ãã®ã¯ã©ãŠãã¹ãã¬ãŒãžãµãŒãã¹ã®1ã€ã«ãããŸãããããŒãºã«æé©ãªå¥ã®ãµãŒãã¹ã䜿çšã§ããŸããããã®ãããªæé©åã¯ãªããçŽæ¥ããŠã³ããŒãããµããŒãããŠããŸããã
ããŒãäžã®åŠç
ããŒãåŠçäžã®åŠçã¯ãããŒã«ã«ã«ä¿åãããè¿ éã«åŠçãããç»åã«é©ããŠãããšæããŸãã ãã ãããªãªãžãã«ãS3ã«ä¿åãããšãRefileã¯æåã«S3ãããªãªãžãã«ãããŒãããå¿ èŠããããããåæããŒãžã§ã³ãªã¯ãšã¹ãã®åŠçãã¯ããã«é ããªããŸãã ãã®å Žåããã¹ãŠã®ããŒãžã§ã³ãååŠçããããã¯ã°ã©ãŠã³ãã¿ã¹ã¯ãè¿œå ããããšãæ€èšããå¿ èŠããããŸãã
ãããªãªã©ã®å€§ããªãã¡ã€ã«ãããŠã³ããŒãããå Žåã¯ãéåžžãããŠã³ããŒãããã»ã¹äžãããããŠã³ããŒãåŸã«åŠçããããšããå§ãããŸãã ãã ããRefileã¯çŸåšããããµããŒãããŠããŸããã
ãã³ã
ããŒãäžã«åŠçããããã®Ruby gem-ã·ããã©ã®Railsã§ã®ã€ã¡ãŒãžã®ããŒãã«é©ããŠããŸã
Dragonflyã¯ãèªã¿èŸŒã¿äžã«åŠçããããã®å¥ã®ãœãªã¥ãŒã·ã§ã³ã§ãããRefileãããã¯ããã«é·ãã·ãŒã³ã«ãããç§ã®æèŠã§ã¯ãèªã¿èŸŒã¿äžã«ã¯ããã«é«åºŠã§æè»ãªåŠçæ©èœãåããŠããŸãã
Dragonflyã¯Sequelã§åäœããŸãããããã¯äºæ³ãããããšã§ãã¢ããã¿ãŒãäœæããæºåãã§ããŸãããã¢ãã«ã«é¢é£ä»ããããäžè¬çãªåäœ ã¯ActiveRecordã¢ãã«ã«åºæã®åäœãšæ··ããåãããã§ããããããããè¡ãæ¹æ³ã¯æ確ã§ã¯ãããŸããã
ããã¯ã°ã©ãŠã³ãã¿ã¹ã¯ãçŽæ¥ããŠã³ããŒãã®ãµããŒãããããŸããã åŸè ã¯æåã§è¡ãããšãã§ããŸãããPaperclipãšåãæ¬ ç¹ããããŸãã
ããäžã€éèŠãªç¹ããããŸãã ã€ã¡ãŒãžãµãŒããŒïŒããŠã³ããŒãããã»ã¹äžã®åŠççšã®Dragonflyã¢ããªã±ãŒã·ã§ã³ïŒãä»ãããã¡ã€ã«ã®ååŸã¯ãå®å šã«å¥ã®è²¬ä»»ã§ãã ã€ãŸãããã¹ãŠã®ãã®ïŒçŽæ¥ããŠã³ããŒããããã¯ã°ã©ãŠã³ãã¿ã¹ã¯ãããŸããŸãªORMãªã©ïŒã«ä»å±ããå¥ã®ãã¡ã€ã«ã¢ããããŒãã©ã€ãã©ãªã䜿çšããŠããã¡ã€ã«ããªããžããªã«ã¢ããããŒãããåŒãç¶ãDragonflyã䜿çšããŠãããã®ãã¡ã€ã«ãæäŸã§ããŸãã
map "/attachments" do run Dragonfly.app # doesn't care how the files were uploaded end
æ»æ
ãã¡ã€ã«ãããŠã³ããŒãããå¥ã®ã¢ãããŒã
Attacheã¯ãããŒãäžã®åŠçããµããŒãããæ¯èŒçæ°ããã©ã€ãã©ãªã§ãã DragonflyãšRefileã®éãã¯ãAttacheãåå¥ã®ãµãŒãã¹ãšããŠå®è¡ãããããã«èšèšãããŠãããããAttaacheãµãŒããŒãä»ããŠãã¡ã€ã«ãããŠã³ããŒãããå ±æãããããšã§ãã
Attacheã«ã¯ãããŠã³ããŒããããã¡ã€ã«ãããŒã¿ããŒã¹ã¬ã³ãŒãã«ãªã³ã¯ããããã®ActiveRecordçµ±åããããçŽæ¥ããŠã³ããŒãããµããŒããããŠããŸãã ãã ããããã¯ã°ã©ãŠã³ãã¿ã¹ã¯ã§ãã¡ã€ã«ãããã¯ã¢ããããã³åé€ããã«ã¯ããŸã ååãªæ©èœããããŸããã ããã«ãAttacheã«ã¯ååãªæè»æ§ããããŸããã
Dragonflyã®ããã«ãAttacheãã¢ãã«ã«çµ±åããå¿ èŠã¯ãããŸãããããã«ã¯Shrineã䜿çšã§ããŸãã ä»å¹Žãã·ã³ã¬ããŒã«ã®RedDotRubyConfã蚪ããŸãããããã§ãå¶ç¶Attacheã®äœè ãšäŒãããã¡ã€ã«ã®ããŠã³ããŒãã«é¢ããåé¡ã«ã€ããŠéåžžã«èå³æ·±ãè°è«ãããåŸãæ·»ä»ãã¡ã€ã«ã®ããžãã¯ã«Shrineã䜿çšããããã¯ãšã³ããšããŠã
ãã®ããã«ããŠãAttacheã¯ãã¡ã€ã«ãé åžãããšåæã«ãShrineãžã®æ·»ä»ãã¡ã€ã«ã䜿çšããŠäœæ¥ãè¡ãããšãã§ããŸãã
çµè«ãšããŠ
çŽæ¥ããŠã³ããŒãã®ãµããŒããããã¯ã°ã©ãŠã³ãã§ã®ãã¡ã€ã«ã®ç®¡çãèµ·åæã®åŠçãããã³ä»ã®ORMã§äœ¿çšã§ããããšã¯ãã©ã€ãã©ãªã«æ¬åœã«æåŸ ããŠããããšã§ãã ãã ãããããã®èŠä»¶ããã¹ãŠãµããŒãããæ¢åã®ã©ã€ãã©ãªã¯ãããŸããã
ãã®ãããç§ã¯æ¢åã®ã©ã€ãã©ãªã®ç¥èã«åºã¥ããŠæ°ããShrineã©ã€ãã©ãªãäœæããããšã«ããŸããã
Shrineã®ç®æšã¯ããã¡ã€ã«ãæäœãããšãã«ããŸããŸãªã¿ã¹ã¯ãæé©åããæ©èœãšæè»æ§ãæäŸããããã«ãäžåšçšã«ãªãããšã§ã¯ãããŸããã
ããã¯éå¿çãªç®æšã§ããã1幎éã®æŽ»çºãªéçºãšç 究ã®åŸãç§ã¯ãããéæãããšæããŠããŸãã å°ãªããšããä»ã®Rubyã©ã€ãã©ãªãããå€ãã®æ©èœããããŸãã ãã®ã·ãªãŒãºã®æ®ãã®éšåã§ã¯ãShrineã§äœ¿çšã§ãããã¹ãŠã®ã¯ãŒã«ãªæ©èœã玹ä»ããŸãã®ã§ããæåŸ ãã ããïŒ
ãªãªãžãã«ïŒ ShrineïŒMotivationã䜿çšãããã¡ã€ã«ã®ã¢ããããŒãã®æ¹å
èè ã®ããã°ã·ãªãŒãºã®ä»ã®èšäºïŒ
- ShrineïŒUploaderã䜿çšãããã¡ã€ã«ã®ã¢ããããŒãã®æ¹å
- Shrineã«ããããè¯ããã¡ã€ã«ã¢ããããŒãïŒæ·»ä»ãã¡ã€ã«
- Shrineã«ãããã¡ã€ã«ã®ã¢ããããŒãã®æ¹åïŒåŠç
- Shrineã䜿çšãããã¡ã€ã«ã®ã¢ããããŒãã®æ¹åïŒã¡ã¿ããŒã¿