Skip to content

Instantly share code, notes, and snippets.

View is8r's full-sized avatar
🙂

Yu Ishihara is8r

🙂
View GitHub Profile
@is8r
is8r / gist:5610746
Created May 20, 2013 06:42
eachでインデックスも取得する
@xxx.each_with_index do |item, i|
@is8r
is8r / gist:5610757
Created May 20, 2013 06:45
findで最初の行だけ取得
@xxx = Xxx.find(:first)
@is8r
is8r / gist:5626975
Last active December 17, 2015 14:49
他のテーブルの特定のカラムをセレクトメニューにする
= f.label :xxx_id, "xxx"
= f.collection_select :xxx_id, Xxx.all, :id, :name
@is8r
is8r / gist:5635624
Last active December 17, 2015 15:59
コントローラなどからヘルパーメソッドを呼ぶ
#クラスレベルやモデルクラス内
ApplicationController.helpers.xxx(@xxx)
#インスタンスメソッド内
self.class.helpers.xxx(@xxx)
@is8r
is8r / new_gist_file
Created May 24, 2013 13:00
link_toで_blank
= link_to "text", "url", :target=>["_blank"]
@is8r
is8r / gist:5676055
Created May 30, 2013 06:34
development環境のみで表示したいものは
- if Rails.env.development?
@is8r
is8r / gist:5676063
Created May 30, 2013 06:36
herokuにBasic認証をかける
#app/controllers/application_controller.rbに
http_basic_authenticate_with :name => ENV["BASIC_AUTH_NAME"], :password => ENV["BASIC_AUTH_PW"] if Rails.env.production?
$ heroku config:add BASIC_AUTH_NAME=xxxx
$ heroku config:add BASIC_AUTH_PW=xxxx
@is8r
is8r / gist:5689429
Created June 1, 2013 05:54
ActiveRecordのカラムをdestroyしていた場合、該当カラムの有無を検索したい時
if !Xxx.find_by_id(3).nil?
re = Xxx.find(3).name
else
re = "該当のカラムは削除されています。"
end
@is8r
is8r / new_gist_file
Created June 6, 2013 08:33
partialに渡しているlocalsの値が無い時にhaml側でデフォルトの値を設定する
- xxx ||= "デフォルト値"
@is8r
is8r / gist:5787649
Created June 15, 2013 10:20
UINavigationBarの陰を削除
UINavigationBar *navBar = [self navigationBar];
if ([[[UIDevice currentDevice] systemVersion] intValue] == 6) {
[navBar setShadowImage:[[UIImage alloc] init]];
}