Rails 5表单选择标记不显示

时间:2018-01-23 01:32:54

标签: ruby-on-rails materialize

我正在使用MaterializeCss为我的样式创建一个带有RoR的博客应用程序,已经创建了这个:

class Post < ApplicationRecord
  belongs_to :user
  belongs_to :category
  has_many :comments, dependent: :destroy
  validates :title, presence: true, length: { minimum: 5 }
  validates :body, presence: true
end

还有:

class Category < ApplicationRecord
    belongs_to :user
    has_many :posts
    validates :name, presence: true, length: { minimum: 3 }
end

还添加了迁移:

class AddCategoryToPost < ActiveRecord::Migration[5.0]
  def change
    add_reference :posts, :category, foreign_key: true
  end
end

更新:我有这个form_for:

<%= form_for @post do |f| %>
  <% if @post.errors.any? %>
    <ul class="collection with-header">
      <li class="collection-header"><h5><%= pluralize(@post.errors.count, "error") %> prevented this post from saving</h5></li>
      <% @post.errors.full_messages.each do |msg| %>
        <li class="collection-item"><%= msg %></li>
      <% end %>
    </ul>
  <% end %>
  <div class="input-field">
    <%= f.label :title %><br>
    <%= f.text_field :title%>
  </div>

  <div class="input-field">
    <%= f.label :body %><br><br>
    <%= f.hidden_field :body, class: "materialize-textarea", id: :post_body %>
    <trix-editor input="post_body"></trix-editor>
  </div>

  <div class="input-field">
    <%= f.label :category_id %>
    <%= f.collection_select(:category_id, Category.all, :id, :name) %>
  </div>
  <br> <br> <br> <br>
  <div class="right">
   <%= f.submit "Save Post", class: "waves-effect waves-light btn" %>
  </div>  
<% end %>

正如您所看到的,我正在尝试从类别模型列出我的所有类别,但在我的浏览器中我得到了以下结果: Browser View Render the Select with all the Categories

正如你所看到的,它呈现所有类别(javascript,ruby on rails,angularjs,PHP)但是我看不到Select in my New Post Form and Can'单击选择

任何线索?

更新:删除了Materialisecss类,但仍未显示选择输入 Removed MaterializeCss Styles

2 个答案:

答案 0 :(得分:1)

我也有同样的问题。我在我的Css中添加的内容我添加了

select{
 display: block;
}

这解决了问题

答案 1 :(得分:0)

发现问题,它的MaterialiseCss是没有向我显示选择输入,我现在不为什么?回到我的老朋友Bootstrap