LoginSignup
1
4

More than 3 years have passed since last update.

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

Last updated at Posted at 2019-11-17

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で囲むことです.

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