クックパッドはなぜ開発しやすいのか At AWS Summit Tokyo 2015 Developer Conference 2015/06/03
何かの理由で著者IDを付けて回らないといけない場合とか。 url_for(:controller => :books, :action => new, :id => 1, :author_id=63) #=> "/books/1/new?author_id=63" Viewに書き続けるのがしんどい場合、Controllerにdefault_url_optionsを書いてやるといい。 class BooksController < ApplicationController def default_url_options(options={}) options.merge :author_id => @haruki.id end def index end # 省略 end そうすると、Viewでauthor_idを書かなくても、自動的に追加される。url_forに限らず、url_forを使
This guide covers the asset pipeline. After reading this guide, you will know: What the asset pipeline is and what it does. How to properly organize your application assets. The benefits of the asset pipeline. How to add a pre-processor to the pipeline. How to package assets with a gem. 1 What is the Asset Pipeline?The asset pipeline provides a framework to handle the delivery of JavaScript and CS
まず、ここまでで一旦整理する。 Time.nowはRubyの組み込みなのでシステムのタイムゾーンしか見ない。OSの時間と常に一致する。Time.localの出力結果もOSのタイムゾーンと一致する。 TimeWithZoneクラスはconfig.time_zoneに左右される。 Ruby組み込みのメソッドで取得したUTCの時間を基準に、設定されているタイムゾーンの時間に変換する。 ActiveRecordのインスタンスに対してアクセサを利用して時間をやり取りする場合はTimeWithZoneで行われる。 仮にTimeクラスを渡しても代入時にTimeWithZoneに変換される。 config.active_record.default_timezoneの設定はDBを読み書きする際に、DBに記録されている時間をTime.utcで読むかTime.localで読むかを設定する。 :utcの場合DB
絶賛運営中のトーナメント表作成サービス「THE TOURNAMENT(ザ・トーナメント)」。 今回はRails多言語対応のi18nをつかって英語版に切替れるようにしてみました。 i18n対応でいろいろハマったりしたところのまとめです。 まずは基本的なやり方とか i18nの使い方については公式ドキュメントに詳しく載ってます。困ったときはちゃんと読めば書いてある。 RailsGuides「Rails Internationalization (I18n) API」 あとはいつものようにmorizyunさんのブログも参考にさせてもらいました。 酒と泪とRubyとRailsと「Railsの多言語化対応 I18nのやり方を整理してみた!【国際化/英語化】」 まずはこのあたりを読み込んでその通りにやっていけば基本的な設定はできるはず。 以下さらに詳細な設定やハマったところとかのまとめです。 sha
Twitter Bootstrap 3がリリースされてから結構日が経ちますが、twitter-bootstrap-railsはブランチ版で、simple_formはRC版でそれぞれ対応できているようです。導入するにあたって、ちょっとハマる箇所もあったので、簡単にチュートリアルにまとめておきたいと思います。 環境 Mac OS X 10.8 Ruby 2.1 Ruby on Rails 4.1 twitter-bootstrap-rails 3.1.1 (2014/6/21時点ではbranch) simple_form 3.1.0.rc セットアップ Gemfileに必要なgemを記述します。ポイントはtwitter-bootstrap-railsとsimple_formです。各々最新安定版ではまだ対応していないので(2014/6/21現在)、以下のようにバージョン指定が必要です。 📄Ge
Egor Homakov recently brought to my attention a slight problem with how Paperclip handles some content type validations. Namely, if an attacker puts an entire HTML page into the EXIF tag of a completely valid JPEG and named the file “gotcha.html”, they could potentially trick users into an XSS vulnerability. Now, this is kind of a convoluted means of attacking. It involves: A server that’s running
File: determine file type Version 5.03 Description File tests each argument in an attempt to classify it. There are three sets of tests, performed in this order: filesystem tests, magic number tests, and language tests. The first test that succeeds causes the file type to be printed. The type printed will usually contain one of the words text (the file contains only printing characters and a few c
さくらVPSで先月と今月、勝手に再起動かかってサービス動いてないのにしばらく気づけなかったのでunicornの自動起動設定してみた ぐぐった先からシェルもらってきて動かしたけど unicorn not found って言われた 調べたらrvm使ってたらラッパーなるものを作りなさいと rvm wrapper 2.0.0@default start unicornするとホームにstart_unicornっていうリンクファイルができるのでこれを呼ぶように変更 /home/ubuntu/.rvm/bin/start_unicornシェルスクリプト /etc/init.d/unicorn #!/bin/sh NAME="Unicorn" ENV=production ROOT_DIR="/var/www/blog" PID="${ROOT_DIR}/tmp/pids/unicorn.pid" CON
追記 13/11/07 statusがうまく機能しないようです。すいません。 ubuntu12.04.03でunicornを使うrubyのアプリを自動起動するスクリプトです。 主にrailsで作ったアプリを想定しています。 参考にした本はこちら:Ruby on Rails環境構築ガイド なお,unicorn自体の起動コマンドは,下記の通り。 $cd /path/to/rubyapp/ $bundle exec unicorn_rails -c config/unicorn.rb -E production -D 環境 アプリを起動するユーザ:test アプリのホーム:/home/test/rubyapp 最初に,空の起動スクリプトを作成。 sudo nano /etc/init.d/rubyapp #! /bin/sh ### BEGIN INIT INFO # Provides: tes
Single Table Inheritanceで親子関係にある二つのクラスHoge, Fugaがあるとする。 class Hoge < ActiveRecord::Base end class Fuga < Hoge end このときHogeクラスのオブジェクトaがあったとしてそれをFugaクラスに変換したいとする。 そもそもそういう状況がオブジェクト指向的にどうなのかというのは置いておく。 このとき、 a = Hoge.find(1) b = a.becomes(Fuga) b.save! とすればいいのかと思って試してみるも、ロードしなおしたオブジェクトはHogeクラスのままだった。 オブジェクトを保存するときのクエリーを見ると次のようになっていた。 UPDATE `hoges` SET `type` = 'Fuga', `updated_at` = '2013-04-08 14:0
Rails STI and form_forWritten August 14, 2012. Tagged Ruby on Rails, STI. Rails' form_for conveniently uses "record identification" to figure out the correct URL based on the model: = form_for([:admin, @item]) do |f| = f.text_field :nameIt's also used to figure out the HTTP verb, the field name prefixes, HTML classes and HTML id. So this form would POST to admin_items_path for a new record, or PUT
Slim is a template language whose goal is to reduce the view syntax to the essential parts without becoming cryptic. It started as an exercise to see how much could be removed from a standard html template (<, >, closing tags, etc...). As more people took an interest in Slim, the functionality grew and so did the flexibility of the syntax. A short list of the features... Elegant syntax Short synta
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く