LoginSignup
0
0

More than 3 years have passed since last update.

Rails学習メモ(自分用)

Last updated at Posted at 2019-12-20

from : パーフェクトRuby on Rails
https://www.amazon.co.jp/dp/B00P0UR1RU/ref=dp-kindle-redirect?_encoding=UTF8&btkr=1

※原書がRails4基準な上、実機では試していないオプション等もあるため、自己責任で参照してくださいね。

バリデーション一覧

バリデーション名 内容
validates_associated 関連先のレコードがvalid
confirmation emailなど、確認フィールドと内容が一致すること
exclusion ある値でないこと
format あるフォーマットを満たすこと
inclusiomn ある値の中に含まれること
length ある長さを満たすこと
numericality 数値であること、ゼロ以上か?偶数か?も検査可能
presence 存在すること
absence 存在しないこと
uniqueness 値が一意であること

コールバックポイント一覧

コールバックポイント名と呼ばれるタイミングの照応表

コールバックポイント create update destroy
bef/aft_validation o o x
bef/aro_save o o x
bef/aro/aft_create o x x
bef/aro/aft_create x o x
bef/aro/aft_destroy x x o
after_save o o x
  • bef ... before
  • aro ... around
  • aft ... after
    コールバックが呼ばれないメソッド

    • decrement
    • decrement_counter
    • delete
    • delete_all
    • increment
    • increment_counter
    • toggle
    • touch
    • update_column
    • update_columns
    • update_all
    • update_counters

renderメソッドのオプション

renderオプション 内容 サンプル
:plain text/plainでテキストをそのまま表示する render plain:"OK"
:html text/htmlでテキストをそのまま表示する render html:"OK"
:body 生データをブラウザにそのまま帰す render body:"data"
:nothing 明示的に何も表示しない render nothing:true
:template 特定のテンプレートを指定してレンダリング render template "submit/edit.html.erb"
:file 特定のファイルの内容をそのまま表示する render file:'Rails.root.join('public.sample.html')'
:json to_jsonを用いてJSONを表示する render json:@submit
:xml to_xmlを用いてXMLを表示する render xml:@submit

↑2019/12/21 2:03

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0