LoginSignup
0
0

More than 1 year has passed since last update.

個人的Railsメモ

Last updated at Posted at 2021-08-31

モデル

複数形がない英単語の対処法

ActiveSupport::Inflectorに個別設定を追加する。

config/initializers/inflections.rb

ActiveSupport::Inflector.inflections do |inflect|
  inflect.singular /^(campus)(es)?$/i, '\1'
  inflect.plural   /^(campus)$/i, '\1es'
end

ビュー

フォーム

複数のチェックボックスのラベルはどう書くか

結論:②の方が良さそう。

①labelで囲む。

<% Table.all.each do |row| %>
    <label>
        <%= form.check_box(:child_ids, { multiple: true }, row.id, nil) %>
        <img src="<%= asset_path(row.file_path) %>" alt="<%= row.name %>">
    </label>
<% end %>

②値をシンボル化する

Array.each do |value|
    form.radio_button(name, value.to_s.to_sym)
    form.label("#{name.to_s}_#{value.to_s}".to_sym)
end
0
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
0
0