gpt4 book ai didi

ruby-on-rails - Rails API 应用程序 : (No MethodError) when I run foreman start

转载 作者:数据小太阳 更新时间:2023-10-29 08:18:45 25 4
gpt4 key购买 nike

我刚刚创建了一个新的 Rails API 应用程序,我正在尝试第一次运行它。我安装了 foreman gem 并使用命令

  foreman start

启动服务器但我收到这些错误:

 Exiting
21:52:55 web.1 |
/Users/AM/Documents/RailsWS/app1229/config/initializers/wrap_parameters.rb:8:in
`block in <top (required)>':
undefined method `wrap_parameters' for ActionController::API:Class (NoMethodError)
21:52:55 web.1 |
from /Users/AM/.rvm/gems/ruby-1.9.3-p194-gemset/gems/activesupport-
3.2.8/lib/active_support/lazy_load_hooks.rb:36:in `instance_eval'
21:52:55 web.1 |
from /Users/AM/.rvm/gems/ruby-1.9.3-p194-gemset/gems/activesupport-
3.2.8/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook'
21:52:55 web.1 |
from /Users/AM/.rvm/gems/ruby-1.9.3-p194-gemset/gems/activesupport-
3.2.8/lib/active_support/lazy_load_hooks.rb:26:in `block in on_lo
..........

我已经尝试更新 gemset 并重新测试终端等。

但是没有任何效果。想知道是否有人可以给出关于如何继续诊断此错误来源的想法

谢谢


编辑下面是 ApplicationController.rb 的内容

 class ApplicationController < ActionController::API 
include ActionController::MimeResponds
include ActionController::ImplicitRender

end

gem 文件:

 source 'https://rubygems.org'
gem 'rails', '3.2.8'
gem 'rails-api'
gem 'pg'
gem 'thin'
gem 'foreman'
gem 'rabl'
gem "paperclip"
gem 'aws-sdk'
group :development do
gem 'annotate', :git=>'git://github.com/ctran/annotate_models.git'
gem 'debugger'
end

错误指向此文件中的第 8 行:wrap_parameters.rb

 # Be sure to restart your server when you modify this file.
#
# This file contains settings for ActionController::ParamsWrapper which
# is enabled by default.

# Enable parameter wrapping for JSON. You can disable this by setting :format to an
empty array.
ActiveSupport.on_load(:action_controller) do
ERROR >>>> wrap_parameters format: [:json]
end

# Disable root element in JSON by default.
ActiveSupport.on_load(:active_record) do
self.include_root_in_json = false
end

最佳答案

wrap_parameters 中的问题在 rails-api 版本 0.0.3 中已修复,但对于以前生成的应用程序,我们必须用 initializers/wrap_parameters.rb 中的第一段代码替换此代码:

ActiveSupport.on_load(:action_controller) do
include ActionController::ParamsWrapper
wrap_parameters format: [:json] if respond_to?(:wrap_parameters)
end

我现在已经在我的一个 heroku 应用程序中对其进行了测试,并且运行良好。不再需要在全功能 rails 中重写代码 :)

关于ruby-on-rails - Rails API 应用程序 : (No MethodError) when I run foreman start,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14088669/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com