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

时间:2013-04-11 09:26:17

标签: ruby-on-rails ruby-on-rails-3

我正在尝试使用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.

我已经查过,但我没有评论控制器。这些是我尝试的命令: -

$ 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帮帮我。

这是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'

3 个答案:

答案 0 :(得分:3)

active_admin gem使用相同的名称comments。这就是rails生成器不允许您创建comments controller的原因。请参阅:github.com/gregbell/active_admin/tree/master/lib/active_admin。在这里,您可以看到comments目录。因此,最好为控制器使用其他名称以避免出现问题。

答案 1 :(得分:1)

如果您不需要管理部分中的评论,则可以将其关闭。

转到/config/initializers/active_admin.rb并撰写config.allow_comments = false。完成此操作后,您可以生成控制器,并且不会与active_admin冲突。

您可以阅读active admin documentation了解详情。

答案 2 :(得分:0)

我刚刚手动创建了comments_controller,它正在运行。 active_admin可能是一个问题。我问了一位朋友,但他没有遇到active_admin的任何问题。所以,我不确定问题是什么,但现在,手动创建控制器。