Railsのお勉強備忘録


config.assets.enabled = false
config.active_record.table_name_prefix = "northwest_"
config.active_record.default_timezone = :local
config.active_record.schema_format = :sql

<% cache [ "v1", @hoge ] do %>
delegate :name, to: :user, allow_nil: true
allow_nil指定でuser.try(:name)と同じ
'author_id'.humanize
# "Author"
"active model".camelize
=> "Active model"
<%= render 'product', object: product %>
=> _product.html.erb

<%= render @products %>
=> _product.html.erb

<%= render partial: "product", locals: {product: @product} %>
=> _product.html.erb

@request.user_agent = "iPhone"
@response.user_agent => NG
@request == request => true
request.headers["HTTP_USER_AGENT"] => OK
request["headers"]["HTTP_USER_AGENT"] => NG
response.headers["HTTP_USER_AGENT"] => OK
mail to: email, subject: 'test'
何も指定しなければhtmltextも送信可能
namespace :task_name do
  desc "実行処理の説明"
  task :create, ['name'] => :environment do |task, args|
    args.name
  end
end

http://qiita.com/yoshiokaCB/items/c97ba878469701c3d99b ここ参考!!

assert_difference
assert_difference(User, :count, 1)

before_validation -> after_validation -> before_save -> before_update -> after_update -> after_save
http_basic_authenticate_with name: 'hoge', password: 'hogehoge'

def authenticate
  authenticate_or_request_with_http_basic('Administration') { |username, password|
    username == 'hoge' && password == 'hogehoge'
  }
end
<%= f.hidden_field :lock_version %>
楽観的ロックには必須
gteq => WHERE (`users`.`age` >= 20)
lteq => WHERE (`users`.`age` <= 60)

http://api.rubyonrails.org/classes/ActionView/Helpers/NumberHelper.html
http://api.rubyonrails.org/classes/ActionController/Metal.html
http://api.rubyonrails.org/classes/ActiveRecord/Store.html
http://stackoverflow.com/questions/3664024/select-with-find-in-batches-in-rails
http://easyramble.com/rails-active-record-serialize.html

Assets マニフェスト
http://qiita.com/samurairunner/items/da22eddb64e867b4e145
find_by_sql
http://takumi-skillup.blogspot.jp/2009/05/railssql.html