vendredi 26 janvier 2018

How to get a hash in a Rails form

I have a Rails model with 2 fields: 'name' and 'bucket'. Name is a string and bucket is a hash of the form: bucket: {red: 1, green: 2, ...}.

I created a rails form to populate these fields but while name works properly, the rest don't even appear as values.

This is the point that it doesn't work, when I am trying to bind a color to a value provided by the user, with default value 0.

<% @board.fetch_all_colors.each do |color|  %>
    <%= form.label color.to_sym, "#{color}:" %>
    <div class="input">
      <%= form.text_field :bucket, value: 0.0 %>
    </div>
<% end %>

The thing is that when I debug and print params, I only find an empty bucket hash. Where does my input from text_field go?




Aucun commentaire:

Enregistrer un commentaire