【问题标题】:Select option does not work in Rails using MaterializeCSS选择选项在使用 MaterializeCSS 的 Rails 中不起作用
【发布时间】:2016-07-03 13:47:48
【问题描述】:

我的 form_for 在 rails 中有一个选择选项。在我安装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%>

【问题讨论】:

    标签: ruby-on-rails form-for materialize


    【解决方案1】:

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

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

    更多详情,请查看MaterializeCSS docs

    【讨论】:

      【解决方案2】:

      只要我的两分钱:

      MaterializeCSS 现在是 1.0.0 版本,所以不是

      $('select').material_select();
      

      你会使用

      $('select').formSelect();
      

      【讨论】:

        猜你喜欢
        • 2017-04-26
        • 1970-01-01
        • 1970-01-01
        • 2018-04-12
        • 1970-01-01
        • 2020-05-01
        • 2013-08-08
        • 1970-01-01
        • 2020-10-31
        相关资源
        最近更新 更多