0

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

请帮帮我。

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

3 回答 3

3

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

于 2013-04-11T10:20:24.257 回答
1

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

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

您可以阅读活动管理文档以获取更多信息。

于 2013-08-02T10:33:35.733 回答
0

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

于 2013-04-11T10:30:14.540 回答