所以我正在尝试运行rails console但是我收到以下错误:
/var/lib/gems/2.3.0/gems/actionpack-5.1.3/lib/action_dispatch/http/response.rb:89:in `<class:Response>': undefined method `cache_control' for class `ActionDispatch::Response' (NameError)
from /var/lib/gems/2.3.0/gems/actionpack-5.1.3/lib/action_dispatch/http/response.rb:35:in `<module:ActionDispatch>'
from /var/lib/gems/2.3.0/gems/actionpack-5.1.3/lib/action_dispatch/http/response.rb:6:in `<top (required)>'
from /var/lib/gems/2.3.0/gems/actionpack-5.1.3/lib/action_controller/metal/live.rb:1:in `require'
from /var/lib/gems/2.3.0/gems/actionpack-5.1.3/lib/action_controller/metal/live.rb:1:in `<top (required)>'
from /var/lib/gems/2.3.0/gems/actionpack-5.1.3/lib/action_controller.rb:4:in `require'
from /var/lib/gems/2.3.0/gems/actionpack-5.1.3/lib/action_controller.rb:4:in `<top (required)>'
from /var/lib/gems/2.3.0/gems/actionpack-5.1.3/lib/action_controller/railtie.rb:2:in `require'
from /var/lib/gems/2.3.0/gems/actionpack-5.1.3/lib/action_controller/railtie.rb:2:in `<top (required)>'
from /var/lib/gems/2.3.0/gems/activerecord-5.1.3/lib/active_record/railtie.rb:9:in `require'
from /var/lib/gems/2.3.0/gems/activerecord-5.1.3/lib/active_record/railtie.rb:9:in `<top (required)>'
from /var/lib/gems/2.3.0/gems/railties-5.1.3/lib/rails/all.rb:14:in `require'
from /var/lib/gems/2.3.0/gems/railties-5.1.3/lib/rails/all.rb:14:in `block in <top (required)>'
from /var/lib/gems/2.3.0/gems/railties-5.1.3/lib/rails/all.rb:12:in `each'
from /var/lib/gems/2.3.0/gems/railties-5.1.3/lib/rails/all.rb:12:in `<top (required)>'
from /home/isaac/buzzrails/config/application.rb:3:in `require'
from /home/isaac/buzzrails/config/application.rb:3:in `<top (required)>'
from /var/lib/gems/2.3.0/gems/spring-2.0.2/lib/spring/application.rb:92:in `require'
from /var/lib/gems/2.3.0/gems/spring-2.0.2/lib/spring/application.rb:92:in `preload'
from /var/lib/gems/2.3.0/gems/spring-2.0.2/lib/spring/application.rb:153:in `serve'
from /var/lib/gems/2.3.0/gems/spring-2.0.2/lib/spring/application.rb:141:in `block in run'
from /var/lib/gems/2.3.0/gems/spring-2.0.2/lib/spring/application.rb:135:in `loop'
from /var/lib/gems/2.3.0/gems/spring-2.0.2/lib/spring/application.rb:135:in `run'
from /var/lib/gems/2.3.0/gems/spring-2.0.2/lib/spring/application/boot.rb:19:in `<top (required)>'
from /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from -e:1:in `<main>'
我试过重新启动弹簧,但它没有用。有任何想法吗?
编辑:这是我的config / application.rb:
require_relative 'boot'
require 'rails/all'
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
module Buzzbomb
class Application < Rails::Application
# Initialize configuration defaults for originally generated Rails version.
config.load_defaults 5.1
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
end
end
这是我的宝石文件:
source 'https://rubygems.org'
git_source(:github) do |repo_name|
repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
"https://github.com/#{repo_name}.git"
end
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.1.3'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# Use Puma as the app server
gem 'puma', '~> 3.7'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.2'
# 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'
# 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 :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
# Adds support for Capybara system testing and selenium driver
gem 'capybara', '~> 2.13'
gem 'selenium-webdriver'
end
group :development do
# Access an IRB console on exception pages or by using <%= console %> anywhere in the code.
gem 'web-console', '>= 3.3.0'
gem 'listen', '>= 3.0.5', '< 3.2'
# 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]
gem 'nokogiri'
gem 'typhoeus'
gem 'json'
gem 'tux'
我不确定我做错了什么 - 感谢任何建议,在nginx服务器上运行。它在本地工作但我在服务器上执行“rails console”时出错。
我在从Rails 4升级到Rails 5时遇到了同样的错误,结果证明我的Gemfile.lock中存在错误的合并。
我重新捆绑(bundle update rails
),现在又重新开始了。
使用rails new my_api --api
生成项目
gem 'actionpack-action_caching'
caches_action :index
并得到错误:
app/controllers/api/v1/traces_controller.rb:10:inclass:TracesController': undefined method caches_action' for Api::V1::TracesController:Class (NoMethodError)
UPD好的,如果你的应用程序控制器继承自ActionController :: API,只需:
include ActionController::Caching in application_controller.