【Rails】form_withをSlimで書いてCheckBoxを横並びにした
はじめに
Railsでテンプレートにslimを使ったform_withの実装で若干苦戦したので、まとめてみました!
今回はCSSのフレームワークにSpectreを使っています。
(Bootstrapでも同様にできると思います。)
Slimになかなか慣れない…
環境
- Ruby 2.6.3
- Rails 5.2.3
通常のform_withの書き方
hoge.html.slim
section.hoge-list
h4 メール配信を希望の方はチェック
= form_with(model: [:ops, @user], local: true) do |f|
.form-group
= f.check_box :hoge_column, class: 'form-control'
= f.label :hoge_column, '配信する', class: 'form-label'
.form-group
= f.submit
ブラウザでは以下のようになる
これではUIが良くないためスタイルを整える必要がある
インデント、Spectreを使いスタイルを整える
hoge.html.slim
section.hoge-list
h4 メール配信を希望の方はチェック
= form_with(model: [:ops, @user], local: true) do |f|
.form-group
= f.label :hoge_column, class: 'form-label form-switch'
= f.check_box :hoge_column, class: 'form-control'
|
i.form-icon
strong 配信する
br
.form-group
= f.submit
Author And Source
この問題について(【Rails】form_withをSlimで書いてCheckBoxを横並びにした), 我々は、より多くの情報をここで見つけました https://qiita.com/naocan/items/60232cd96b15cb298f43著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .