1

I have a select option in my form_for in rails. It was working before I installed materialize but after installing it, it doesnt work anymore. Please see my code below:

Game model

class Game < ActiveRecord::Base

    GENRES = ['Action', 'Adventure', 'RPG', 'Simulation', 'Strategy', 'Sports', 'Others']
    PLATFORMS = ['3DS', 'WII U', 'NX', 'PC', 'Playstation', 'XBOX', 'PS Vita', 'Mobile', 'Others']

end

new.html.erb

<h1> Add Game </h1>

<%= form_for :game, url: games_path do |f| %>
    Title: <%= f.text_field :title %> <br />
    Genre: <%= f.collection_select :genre, Game::GENRES, :to_s, :to_s, :include_blank => true %> <br />
    Platform: <%= f.collection_select :platform, Game::PLATFORMS, :to_s, :to_s, :include_blank => true %> <br />
    Release Date: <%= f.date_field :release_date %> <br />
    Progress: <%= f.number_field :progress %> <br />
    Rating: <%= f.number_field :rating %> <br />

    <%= f.submit 'Add Game', class: 'add_game_button' %>
<%end%>
Allan Pereira
  • 2,572
  • 4
  • 21
  • 28
Bill
  • 87
  • 2
  • 10

2 Answers2

3

MaterializeCSS uses a custom implementation of select element, that you have to initialize manually, using jQuery:

$(document).ready(function() {
    $('select').material_select();
});

For more details, check MaterializeCSS docs.

Allan Pereira
  • 2,572
  • 4
  • 21
  • 28
1

Just my two cents:

MaterializeCSS is in version 1.0.0 now, so instead of

$('select').material_select();

you will use

$('select').formSelect();
Thiago
  • 431
  • 5
  • 6