4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

slimでinputやradioとかcheckboxでchecked属性を動的に付ける

Last updated at Posted at 2018-05-19

いつもどうやるんだっけ??と嵌るので備忘録

結論

checked属性の後に=(式)と書けば式の結果がtrueならcheckedが入る falseなら入らない
たとえばUserクラスにadmin?メソットがある場合など

input(type="checkbox" checked=(@user.admin?)) //=> <input checked type="checked">

なんかわかりにくいですよね。
checked if @user.admin? だっけ?
#{"chekced" if @user.admin? } だっけ?
(checked if @user.admin?) だっけななぁ〜?
って、いつも思っちゃうんですよねぇ

4
2
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
4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?