Ludvig Sørensen Ludvig Sørensen - 3 months ago 35
Ruby Question

Cant add collection_select while using materialize rails 4.2

I have created a categories model with a migration with a category_id (basically everything Mackenzie Child does in his video from 25minutes) and I want it to show up in my form.

It doesn't work, my

wont show up on screen but it will show up in the source code, and when I 'remove' the css- framework materialize.

My code:

<div class="container">
<div class="row">
<%= form_for @post do |f| %>
<%= f.collection_select :category_id, Category.all, :id, :name, { prompt: "Choose a category" } %>
<%= f.label :title %>
<%= f.text_field :title %>
<div class="row">
<div class="input-field col s12">
<%= f.label :text %>
<%= f.text_area :text, class: "materialize-textarea" %>

<%= f.label :creator %>
<%= f.text_field :creator %><br>
<%= f.submit %>
<% end %>

How it's displayed in the source code:

<select name="post[category_id]" id="post_category_id"><option value="">Choose a category</option>
<option value="1">Marketing</option>
<option value="2">Technology</option>
<option value="3">Programming</option>
<option value="4">Health and Fitness</option>


I looked in the materialize documentation and i found out that i just had to add the class browser-default to my collection-select (link to docs

    <%= f.collection_select :category_id, Category.all, :id, :name, { prompt: "Choose a category" }, class: "browser-default" %>