LoginSignup
7
8

More than 5 years have passed since last update.

Rails備忘録

Posted at
  • 複数のラジオボタンを使いたい時
class User < ActiveRecord::Base

  enum test: { foo: 1, bar: 2, piyo: 3 }

end

モデルで定義したenumform_forで使えるみたいです。

<%= form_for(@user) do |f| %>
  <%= f.radio_button :test, :foo, label: "設定1", inline: true %>
  <%= f.radio_button :test, :bar, label: "設定2", inline: true %>
  <%= f.radio_button :test, :piyo, label: "設定3", inline: true %>
<% end %>

true・falseで使うラジオボタンしか知らなかったので、とても勉強になりました。

7
8
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
7
8