简体   繁体   English

Rails生成控制器注释抛出错误

[英]rails generate controller comments throwing error

I am trying to generate comments controller using rails generate command but it is giving a weird error:- 我正在尝试使用rails generate命令生成注释控制器,但它给出了一个奇怪的错误:-

$ rails generate controller comments
The name 'CommentsController' is either already used in your application or reserved by Ruby on Rails. Please choose an alternative and run this generator again.

I have checked but I don't have a comment controller. 我已经检查过,但没有评论控制器。 These are the commands I have tried:- 这些是我尝试过的命令:

$ rails generate controller Comments create
The name 'CommentsController' is either already used in your application or reserved by Ruby on Rails. Please choose an alternative and run this generator again.

$ rails generate controller comments
The name 'CommentsController' is either already used in your application or reserved by Ruby on Rails. Please choose an alternative and run this generator again.

$ rails g controller Comments
The name 'CommentsController' is either already used in your application or reserved by Ruby on Rails. Please choose an alternative and run this generator again

Plz help me out here. 请帮我在这里。

This is the GemFile:- 这是GemFile:-

source 'http://rubygems.org'

gem 'rails', '3.2.13'
gem 'bootstrap-sass', '2.1'

# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'

gem 'sqlite3'
gem 'mysql'
gem 'activeadmin'
gem "meta_search",    '>= 1.1.0.pre'
gem 'formtastic'


# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sass-rails',   '~> 3.2.3'
  gem 'coffee-rails', '~> 3.2.1'

  # See https://github.com/sstephenson/execjs#readme for more supported runtimes
  # gem 'therubyracer', :platforms => :ruby

  gem 'uglifier', '>= 1.0.3'
end

gem 'jquery-rails'
group :development, :test do
  gem 'rspec-rails', '~> 2.11.0'
  gem 'factory_girl_rails', '~> 3.5.0'
  gem 'capybara', '~> 1.1.2'
  gem 'guard-rspec', '~> 1.2.0'
end

# To use ActiveModel has_secure_password
gem 'bcrypt-ruby', '~> 3.0.0'

# To use Jbuilder templates for JSON
# gem 'jbuilder'

# Use unicorn as the app server
# gem 'unicorn'

# Deploy with Capistrano
# gem 'capistrano'

# To use debugger
# gem 'debugger'

active_admin gem is using the same name comments . active_admin gem使用相同名称的comments That is why rails generator not letting you to create comments controller . 这就是为什么rails generator不允许您创建comments controller See this: github.com/gregbell/active_admin/tree/master/lib/active_admin. 看到这个:github.com/gregbell/active_admin/tree/master/lib/active_admin。 Here you can see comments directory. 在这里您可以看到comments目录。 So it is better to use some other name for your controller to avoid problems. 因此,最好为控制器使用其他名称以避免问题。

If you do not need the comments in your admin section then you can turn it off. 如果您不需要管理部分中的评论,则可以将其关闭。

Go to /config/initializers/active_admin.rb and write config.allow_comments = false . 转到/config/initializers/active_admin.rb并写入config.allow_comments = false Once this is done you can generate your controller and there will be no conflict with active_admin. 完成此操作后,您可以生成您的控制器,并且不会与active_admin发生冲突。

You can read active admin documentation for more information. 您可以阅读有效的管理员文档以了解更多信息。

I just created the comments_controller manually and it is working. 我刚刚手动创建了comments_controller ,它正在工作。 active_admin might be an issue. active_admin可能是一个问题。 I asked a friend but he did not face any such problems with active_admin . 我问了一个朋友,但他的active_admin并没有遇到任何此类问题。 So, I am not sure what the problem was but right now, creating the controller manually works. 因此,我不确定问题出在哪里,但是现在,手动创建控制器是可行的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM