2

我刚刚创建了一个新的 Rails API 应用程序,我第一次尝试运行它。我安装了工头 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

宝石文件:

 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
4

2 回答 2

9

The problem in the wrap_parameters is fixed in version 0.0.3 of rails-api, but for previously generated applications we have to substitute the first block of code in initializers/wrap_parameters.rb for this one:

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

I've tested it right now in one of my heroku apps and works perfectly. No need to rewrite the code in full featured rails anymore :)

于 2013-01-11T10:51:03.633 回答
0

Procfile的 Rails 项目目录的根目录中有一个吗?对于最简单的设置,我的 Procfiles 通常如下所示:

web: bundle exec thin start -p $PORT

(当然gem 'thin',您的 Gemfile 中也需要。)

于 2012-12-30T06:06:35.673 回答