当我运行foreman start时,Rails API app :( No MethodError)

时间:2012-12-30 05:58:46

标签: ruby-on-rails ruby api foreman

我刚创建了一个新的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并重新设置终端等。

然而没有任何效果。想知道是否有人可以就如何继续诊断此错误来源提出想法

由于


EDIT 以下是ApplicationController.rb的内容

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

 end

的Gemfile:

 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

2 个答案:

答案 0 :(得分:9)

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应用程序中对它进行了测试并且运行良好。无需再重写全功能轨道中的代码:)

答案 1 :(得分:0)

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

web: bundle exec thin start -p $PORT

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