AxleMax
AxleMax

Reputation: 149

Rails parameter not being passed on post

In the controller for this (index) view the variable @eventtypes is assigned 4 values (sport, concert, comedy & theatre)

Then the form below retrieves the 4 options and shows them in a drop down menu (HTML select box)

Problem: When I submit this form the index view shows the eventname & number but the eventtype is blank. I am a total noob but I suspect that I need to have an "f." something in the line that begins "<%= select".

Please help me to understand the solution. I am using the latest Rails 4 and Ruby 2.0.0

<%= form_for(@tix) do |f| %>
  <div class="field">
    <%= f.label :eventname %><br>
    <%= f.text_field :eventname %>
  </div>
  <div class="field">
    <%= f.label :eventtype %><br>
    <%= select(:eventtype, :eventtype, @eventtypes.collect {|e| [ e.category, e.id ] })  %>
  </div>
  <div class="field">
    <%= f.label :price %><br>
    <%= f.number_field :price %>
  </div>
  <div class="actions">
    <%= f.submit %>
  </div>
<% end %>

Upvotes: 1

Views: 100

Answers (2)

mu is too short
mu is too short

Reputation: 434665

You're probably picking up Kernel#select when you say:

<%= select(:eventtype, :eventtype, @eventtypes.collect {|e| [ e.category, e.id ] })  %>

You want the select form helper:

<%= f.select(...

Consult the documentation for the correct arguments.

Upvotes: 1

AxleMax
AxleMax

Reputation: 149

The correct syntax was

<%= f.select(:eventtype, @eventtypes.collect {|p| [p.category] }, { include_blank: true }) %>

Note: The link http://api.rubyonrails.org/classes/ActionView/Helpers/FormBuilder.html#method-i-select has incorrect syntax as it is missing a '(' before the first ':eventtype'

Upvotes: 0

Related Questions