问题
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%>
回答1:
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.
回答2:
Just my two cents:
MaterializeCSS is in version 1.0.0 now, so instead of
$('select').material_select();
you will use
$('select').formSelect();
来源:https://stackoverflow.com/questions/38170589/select-option-does-not-work-in-rails-using-materializecss