本文介绍了选择选项在使用MaterializeCSS的Rails中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在rails的form_for中,我有一个select选项.在安装实现之前,它一直在工作,但是在安装之后,它不再起作用.请在下面查看我的代码:
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:
游戏模型
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
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手动对其进行初始化:
MaterializeCSS uses a custom implementation of select
element, that you have to initialize manually, using jQuery:
$(document).ready(function() {
$('select').material_select();
});
有关更多详细信息,请检查 MaterializeCSS文档.
For more details, check MaterializeCSS docs.
这篇关于选择选项在使用MaterializeCSS的Rails中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!