simple_formとは
- formを作るときに便利なgem
- bootstrapと組み合わせると簡単にフォームが作れる
- https://github.com/seyhunak/twitter-bootstrap-rails
simple_formとbootstrapを学ぶなら
- http://www.ohmyenter.com/?p=197
- ↑ bootstrapとの組み合わせが抜群。
generator
rails g scaffold Book title:string author:string review:integer description:text
rake db:migrate
rails g bootstrap:themed Books
- bootstrapのthemedでview/books/*にファイルが作られる
- admin以下にファイルを生成したいとき
rails g bootstrap:themed admin/books book
になる
Usage:
rails generate bootstrap:themed CONTROLLER_PATH [MODEL_NAME] [Specify application layout] [options]
Options:
[--excluded-columns=one two three] # Indicates when to generate excluded columns
Runtime options:
-f, [--force] # Overwrite files that already exist
-p, [--pretend], [--no-pretend] # Run but do not make any changes
-q, [--quiet], [--no-quiet] # Suppress status output
-s, [--skip], [--no-skip] # Skip files that already exist
Description:
Create bootstrap files for themed generator.
collectionの活用
selection
- collectionに配列を指定する
= f.input :source, as: :select, required: true, collection: [["Search", :search], ["Manual", :manual]]
- associationから選択
= f.association :company
simple_enum
= f.input :deliver_cd, collection: f.object.class.delivers.hash