Skip to content

Instantly share code, notes, and snippets.

@shu0115
shu0115 / gist:1178574
Created August 29, 2011 15:09
Ruby1.9.2+Rails3.0.9セットアップ
◆環境
Mac OS X 10.6.8 Snow Leopard
◆インストール対象
Xcode
MacPorts
Git
RVM
Ruby1.9.2
Rails3.0.9
@shu0115
shu0115 / kaminari_install_error
Created February 21, 2012 07:43
Kaminari 0.13.0 Gem Install Error
Gemfile
-----
gem 'kaminari'
-----
$ bundle install
-----
Gem::Package::FormatError: no metadata found in /Users/(USER_NAME)/.rvm/gems/ruby-1.9.3-p125/cache/kaminari-0.13.0.gem
An error occured while installing kaminari (0.13.0), and Bundler cannot continue.
Make sure that `gem install kaminari -v '0.13.0'` succeeds before bundling.
@shu0115
shu0115 / gist:1966599
Created March 3, 2012 15:24
rails newエラー対処
参考:
「Ruby 1.9.3 + Rails 3.2.1 で segmentation fault -> 解決」
- [ http://somethingnew2.com/blog/archives/2012/02/ruby_193_rails_321_segmentation_fault.php ]
-----
rvm remove 1.9.3-p125
export PATH=/usr/bin:/bin:/usr/sbin:/sbin:$HOME/.rvm/bin
rvm pkg install iconv
rvm pkg install openssl
rvm install ruby-1.9.3 --with-openssl-dir=~$rvm_path/usr --with-iconv-dir=$rvm_path/usr
rvm use 1.9.3 --default
@shu0115
shu0115 / gist:2212130
Created March 27, 2012 03:03
controllerとviewの両方からメソッドを呼びたい場合
◆コントローラに書いたメソッドをhelper_methodにする
controllers/application_controller.rb
-----
private
def current_user
@current_user ||= User.where( id: session[:user_id] ).first
end
helper_method :current_user
@shu0115
shu0115 / gist:2212184
Created March 27, 2012 03:18
guard start 「no such file to load -- rspec/matchers/have (LoadError) 」エラー対処
◆Gemfile
----------
group :test do
gem 'rspec', '2.9.0' # Behavior Driven Development (BDD) for Ruby
gem 'rspec-core', '2.9.0' # RSpec runner and example groups.
gem 'rspec-expectations', '2.9.0' # RSpec matchers for should and should_not.
gem 'rspec-mocks', '2.9.0' # RSpec test double framework with stubbing and mocking.
gem 'rspec-rails', '2.9.0' # RSpec version 2.x for Rails version 3.x.
end
----------
@shu0115
shu0115 / gist:2212292
Created March 27, 2012 03:34
where/find/find_by_idのそれぞれのクラス名
◆where
user_test = User.where( :id => 1 )
user_test.class.name # => "ActiveRecord::Relation"
user_test.first.class.name # => "User"
user_test.all.class.name # => "Array"
user_test.all.first.class.name # => "User"
◆find
user_test2 = User.find( 1 )
user_test2.class.name # => "User"
@shu0115
shu0115 / gist:2212617
Created March 27, 2012 04:48
Rails3.2.2 - asset pipelineログ非表示
◆config/environments/development.rb
----------
# Expands the lines which load the assets
# config.assets.debug = true
config.assets.debug = false
----------
@shu0115
shu0115 / gist:2223481
Created March 28, 2012 03:55
Railsでfavicon.icoを表示する設定
◆参考ページ
Railsでfavicon.icoを表示する設定 - hrendohの日記
- [ http://d.hatena.ne.jp/hrendoh/20111102/1320236055 ]
◆アイコンパス設定
app/views/application.html.erb
※「favicon_link_tag」を追加する
-----
<head>
<title>TestList : <%= session[:project_name] %></title>
#resupond_withで質問なのですが、エラーが起きた場合のデフォルトの挙動を変更する場合、
respond_with(@content, :error => 'foo', :location => 'bar')
# とすればいいのでしょうか? #rails_q
@shu0115
shu0115 / gist:2226448
Created March 28, 2012 14:04
Fast Deploy
◆Heroku Deploy For Cedar
git add . && git commit -m "update"
git push heroku master
heroku run rake db:migrate
heroku logs -t
heroku open
◆GitHub Deploy