当我尝试将Rails Admin用于文章时。我收到以下错误。 This Image shows you the error I am facing
这是articles_controller.rb
class ArticlesController < ApplicationController
before_action :set_article, only: [:show, :edit, :update, :destroy]
before_action :authenticate_auth_user!, except: [:index, :show]
# GET /articles
# GET /articles.json
def index
@articles=Article.all
end
# GET /articles/1
# GET /articles/1.json
def show
end
# GET /articles/new
def new
@article = Article.new
end
# GET /articles/1/edit
def edit
end
# POST /articles
# POST /articles.json
def create
@article = Article.new(article_params)
respond_to do |format|
if @article.save
format.html { redirect_to @article, notice: 'Article was successfully created.' }
format.json { render :show, status: :created, location: @article }
else
format.html { render :new }
format.json { render json: @article.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /articles/1
# PATCH/PUT /articles/1.json
def update
respond_to do |format|
if @article.update(article_params)
format.html { redirect_to @article, notice: 'Article was successfully updated.' }
format.json { render :show, status: :ok, location: @article }
else
format.html { render :edit }
format.json { render json: @article.errors, status: :unprocessable_entity }
end
end
end
# DELETE /articles/1
# DELETE /articles/1.json
def destroy
@article.destroy
respond_to do |format|
format.html { redirect_to articles_url, notice: 'Article was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_article
@article = Article.find(params[:id])
@comments = @article.comments.all
@comment = @article.comments.build
end
# Never trust parameters from the scary internet, only allow the white list through.
def article_params
params.require(:article).permit(:title, :meta_description, :description, :category_id, :video)
end
end
&#13;
这是模型中的article.rb文件
class Article
include Mongoid::Document
include Mongoid::Timestamps
has_many :comments
belongs_to :category
field :title, type: String
field :meta_description, type: String
field :description, type: String
field :category_id, type: String
field :video, type: String
end
&#13;
这是我的宝石文件
source 'https://rubygems.org'
ruby "2.3.1"
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.0.0', '>= 5.0.0.1'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# Use Puma as the app server
gem 'puma', '~> 3.0'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0.6'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.2'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.5'
gem 'mongoid', '~>6.0.3'
gem 'carrierwave-mongoid', :require => 'carrierwave/mongoid'
gem 'friendly_id', '~> 5.2'
gem 'devise', '~> 4.2'
gem 'mail_form', '~> 1.6'
gem 'ckeditor', '~> 4.2'
gem 'rails_admin', '~> 1.1'
gem 'twitter-bootstrap-rails', '~> 3.2', '>= 3.2.2'
gem 'bootstrap-sass', '3.2.0.2'
gem 'less-rails', '~> 2.8'
gem 'therubyracer', '~> 0.12.2'
gem 'mongoid-ancestry', '~> 0.4.2'
gem 'simple_form', '~> 3.3', '>= 3.3.1'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 3.0'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
group :production do
gem 'pg', '~> 0.19.0'
gem 'rails_12factor', '~> 0.0.3'
end
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platform: :mri
end
group :development do
# Access an IRB console on exception pages or by using <%= console %> anywhere in the code.
gem 'web-console'
gem 'listen', '~> 3.0.5'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
&#13;
comment.rb
class Comment
include Mongoid::Document
include Mongoid::Timestamps
belongs_to :article
field :name, type: String
field :email, type: String
field :article_id, type: String
field :comment, type: String
end
&#13;
category.rb
class Category
include Mongoid::Document
include Mongoid::Ancestry
has_many :articles
has_ancestry
mount_uploader :image, FileUploader
field :name, type: String
field :image, type: String
field :parent_id, type: String
end
&#13;
我该如何解决这个问题?