LoginSignup
3
0

More than 3 years have passed since last update.

RailsのSlimでフォームに(form_with)Bootstrapを適用させる

Last updated at Posted at 2019-09-02

ぐぐってもすぐに分からなかったので、メモ。
今は、form_withを使ってフォームを作るといいらしい。
フォームにclassを書くには、キーワード引数? classに文字列でクラス名を渡すといいらしい。

Railsの中身読んでも引数の指定の仕方がよくわかりませんでした。
Rails難しい。

app/views/blogs/new.html.slim
= form_with url: blogs_create_path, model: @blog, locale: true do |f|
  .form-group.col-md-6
    = f.label :name
    = f.text_field :title, class: 'form-control'
  .form-group.col-md-6
    = f.label :article
    = f.text_area :article, class: 'form-control'
    = f.submit '新規登録', class: 'btn btn-primary'

参考にさせていただきました。

一日一吉
Ruby学習日記6:Slimを少々

slimで書くformサンプル

【Rails 5】(新) form_with と (旧) form_tag, form_for の違い

Bootstrap
Forms

3
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
3
0