Help us understand the problem. What is going on with this article?

Rails 5 Bootstrap でフォームを作るときのhidden_field_tagの書き方

More than 1 year has passed since last update.

1時間近くハマったので,メモしておきます.

環境

Ruby version: RUBY VERSION: 2.6.3
Rails version: Rails 5.0.7.2

書き方

  <%= form_for(current_user.watch_relations.build) do |f| %>
    <div class="form-group">
      <%= hidden_field_tag :film_id, film.id %>
    </div>

    <div class="form-group">
      <%= f.label :rate, 'rate' %>
      <%= f.number_field :rate, class: 'form-control' %>
    </div>
    <div class="form-group">
      <%= f.label :comment, 'comment' %>
      <%= f.text_field :comment, class: 'form-control' %>
    </div>
    <%= f.submit 'watched', class: 'btn btn-primary btn-block' %>
  <% end %>

ポイントは hidden_field_tagもclass=form-groupのdivで囲むことです.

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away