CaptainCarl
CaptainCarl

Reputation: 3489

Select tag for @group in Rails 4

I've got a select type with 3 fixed options as a clock-type. I can't figure out how to get the clocktype(Which is in my group model) to function properly.

In my HTML it shows the select name as clocktype. In stead of group[clocktype].

Here's my form:

<%= form_for(@group) do |f| %>
  <% if @group.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(@group.errors.count, "error") %> prohibited this group from being saved:</h2>
    </div>
  <% end %>

  <div class="field">
    <%= f.label :name %><br>
    <%= f.text_field :name %>
  </div>

  <%= select_tag(:clocktype, options_for_select([['one', 1], ['two', 2], ['three', 3]])) %>

  <div class="actions">
    <%= f.submit %>
  </div>
<% end %>

Upvotes: 0

Views: 215

Answers (1)

sevenseacat
sevenseacat

Reputation: 25049

You're missing the f. at the front, ie. f.select. This will associate the select tag to the form you've created. Using select_tag alone is for generic forms not specifically associated with a model.

Upvotes: 1

Related Questions