Select 选项在使用 MaterializeCSS 的 Rails 中不起作用

Select option does not work in Rails using MaterializeCSS

我在 rails 中的 form_for 中有一个 select 选项。在我安装 materialize 之前它可以工作,但是在安装它之后,它就不再工作了。请在下面查看我的代码:

游戏模型

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%>

MaterializeCSS 使用 select 元素的自定义实现,您必须使用 jQuery 手动初始化:

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

有关详细信息,请查看 MaterializeCSS docs

只是我的两分钱:

MaterializeCSS 现在是 1.0.0 版,所以

$('select').material_select();

你会用到

$('select').formSelect();