我的API在本地工作但不在heroku上工作

时间:2017-11-07 08:52:56

标签: ruby-on-rails ruby heroku

我的新API在本地运行时有问题,但不是prod(在 Heroku 上)我使用 Grape gem

我正在跑步

heroku run rails console

我有这条消息

Running rails console on ⬢ boiling-temple-35087... up, run.5720 (Free)
[DEPRECATION] This gem has been renamed to hashie-forbidden_attributes and will no longer be supported. Please switch to hashie-forbidden_attributes as soon as possible.
/app/app/api/dimelofone/base.rb:3:in `<class:Base>': uninitialized constant Dimelofone::V1::Objets (NameError)
    from /app/app/api/dimelofone/base.rb:2:in `<module:Dimelofone>'
    from /app/app/api/dimelofone/base.rb:1:in `<top (required)>'
    from /app/vendor/bundle/ruby/2.3.0/gems/activesupport-5.1.4/lib/active_support/dependencies/interlock.rb:12:in `block in loading'
    from /app/vendor/bundle/ruby/2.3.0/gems/activesupport-5.1.4/lib/active_support/concurrency/share_lock.rb:149:in `exclusive'
    from /app/vendor/bundle/ruby/2.3.0/gems/activesupport-5.1.4/lib/active_support/dependencies/interlock.rb:11:in `loading'
    from /app/config/routes.rb:11:in `block in <top (required)>'
    from /app/vendor/bundle/ruby/2.3.0/gems/actionpack-5.1.4/lib/action_dispatch/routing/route_set.rb:426:in `instance_exec'
    from /app/vendor/bundle/ruby/2.3.0/gems/actionpack-5.1.4/lib/action_dispatch/routing/route_set.rb:426:in `eval_block'
    from /app/vendor/bundle/ruby/2.3.0/gems/actionpack-5.1.4/lib/action_dispatch/routing/route_set.rb:408:in `draw'
    from /app/config/routes.rb:1:in `<top (required)>'
    from /app/vendor/bundle/ruby/2.3.0/gems/railties-5.1.4/lib/rails/application/routes_reloader.rb:55:in `block in load_paths'
    from /app/vendor/bundle/ruby/2.3.0/gems/railties-5.1.4/lib/rails/application/routes_reloader.rb:55:in `each'
    from /app/vendor/bundle/ruby/2.3.0/gems/railties-5.1.4/lib/rails/application/routes_reloader.rb:55:in `load_paths'
    from /app/vendor/bundle/ruby/2.3.0/gems/railties-5.1.4/lib/rails/application/routes_reloader.rb:18:in `reload!'
    from /app/vendor/bundle/ruby/2.3.0/gems/railties-5.1.4/lib/rails/application.rb:164:in `reload_routes!'
    from /app/vendor/bundle/ruby/2.3.0/gems/devise-4.3.0/lib/devise/rails.rb:15:in `block in <class:Engine>'
    from /app/vendor/bundle/ruby/2.3.0/gems/activesupport-5.1.4/lib/active_support/lazy_load_hooks.rb:67:in `block in execute_hook'
    from /app/vendor/bundle/ruby/2.3.0/gems/activesupport-5.1.4/lib/active_support/lazy_load_hooks.rb:60:in `with_execution_control'
    from /app/vendor/bundle/ruby/2.3.0/gems/activesupport-5.1.4/lib/active_support/lazy_load_hooks.rb:65:in `execute_hook'
    from /app/vendor/bundle/ruby/2.3.0/gems/activesupport-5.1.4/lib/active_support/lazy_load_hooks.rb:50:in `block in run_load_hooks'
    from /app/vendor/bundle/ruby/2.3.0/gems/activesupport-5.1.4/lib/active_support/lazy_load_hooks.rb:49:in `each'
    from /app/vendor/bundle/ruby/2.3.0/gems/activesupport-5.1.4/lib/active_support/lazy_load_hooks.rb:49:in `run_load_hooks'
    from /app/vendor/bundle/ruby/2.3.0/gems/railties-5.1.4/lib/rails/application/finisher.rb:66:in `block in <module:Finisher>'
    from /app/vendor/bundle/ruby/2.3.0/gems/railties-5.1.4/lib/rails/initializable.rb:30:in `instance_exec'
    from /app/vendor/bundle/ruby/2.3.0/gems/railties-5.1.4/lib/rails/initializable.rb:30:in `run'
    from /app/vendor/bundle/ruby/2.3.0/gems/railties-5.1.4/lib/rails/initializable.rb:59:in `block in run_initializers'
    from /app/vendor/ruby-2.3.4/lib/ruby/2.3.0/tsort.rb:228:in `block in tsort_each'
    from /app/vendor/ruby-2.3.4/lib/ruby/2.3.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
    from /app/vendor/ruby-2.3.4/lib/ruby/2.3.0/tsort.rb:431:in `each_strongly_connected_component_from'
    from /app/vendor/ruby-2.3.4/lib/ruby/2.3.0/tsort.rb:349:in `block in each_strongly_connected_component'
    from /app/vendor/ruby-2.3.4/lib/ruby/2.3.0/tsort.rb:347:in `each'
    from /app/vendor/ruby-2.3.4/lib/ruby/2.3.0/tsort.rb:347:in `call'
    from /app/vendor/ruby-2.3.4/lib/ruby/2.3.0/tsort.rb:347:in `each_strongly_connected_component'
    from /app/vendor/ruby-2.3.4/lib/ruby/2.3.0/tsort.rb:226:in `tsort_each'
    from /app/vendor/ruby-2.3.4/lib/ruby/2.3.0/tsort.rb:205:in `tsort_each'
    from /app/vendor/bundle/ruby/2.3.0/gems/railties-5.1.4/lib/rails/initializable.rb:58:in `run_initializers'
    from /app/vendor/bundle/ruby/2.3.0/gems/railties-5.1.4/lib/rails/application.rb:353:in `initialize!'
    from /app/config/environment.rb:5:in `<top (required)>'
    from /app/vendor/bundle/ruby/2.3.0/gems/railties-5.1.4/lib/rails/application.rb:329:in `require_environment!'
    from /app/vendor/bundle/ruby/2.3.0/gems/railties-5.1.4/lib/rails/command/actions.rb:16:in `require_application_and_environment!'
    from /app/vendor/bundle/ruby/2.3.0/gems/railties-5.1.4/lib/rails/commands/console/console_command.rb:96:in `perform'
    from /app/vendor/bundle/ruby/2.3.0/gems/thor-0.20.0/lib/thor/command.rb:27:in `run'
    from /app/vendor/bundle/ruby/2.3.0/gems/thor-0.20.0/lib/thor/invocation.rb:126:in `invoke_command'
    from /app/vendor/bundle/ruby/2.3.0/gems/thor-0.20.0/lib/thor.rb:387:in `dispatch'
    from /app/vendor/bundle/ruby/2.3.0/gems/railties-5.1.4/lib/rails/command/base.rb:63:in `perform'
    from /app/vendor/bundle/ruby/2.3.0/gems/railties-5.1.4/lib/rails/command.rb:44:in `invoke'
    from /app/vendor/bundle/ruby/2.3.0/gems/railties-5.1.4/lib/rails/commands.rb:16:in `<top (required)>'
    from /app/bin/rails:9:in `require'
    from /app/bin/rails:9:in `<main>'

对于我的routes.rb

Rails.application.routes.draw do
  resources :settings
  get 'homepage/index'

  resources :ligne_cmds
  resources :commands
  devise_for :users
  resources :objets
  # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
  root 'homepage#index'
  mount Dimelofone::Base => '/'
  #mount Root => '/'
end

我的base.rb

module Dimelofone
  class Base < Grape::API
    mount Dimelofone::V1::Objets
    mount Dimelofone::V1::Users
    mount Dimelofone::V1::Commandes
    #mount Dimelofone::V1::Commands
    mount Dimelofone::V1::Settings
  end
end

我无法找到解决方案,我知道它在生产环境中存在问题,但我不知道该怎么办,我几乎可以肯定问题出在这条线上

  

未初始化的常量Dimelofone :: V1 :: Objets(NameError)

这里是objets.rb

module Dimelofone
  module V1
    class Objets < Grape::API
      version 'v1', using: :path
      format :json
      prefix :api
      resource :objets do
  desc "Return list of objets"
  get do
    Objet.all
  end

  desc "Return an objet"
  params do
    requires :id, type: Integer, desc: "Objet id"
  end
  route_param :id do
    get do
      Objet.find(params[:id])
    end
  end
end

  end
end
end

0 个答案:

没有答案