Ruby on rails RubyonRails回调不';我不在Heroku工作,但在本地工作

Ruby on rails RubyonRails回调不';我不在Heroku工作,但在本地工作,ruby-on-rails,ruby,heroku,callback,rails-admin,Ruby On Rails,Ruby,Heroku,Callback,Rails Admin,我一直在使用rails\u admin开发一个学校应用程序。本地的一切都很好,但是当我推到Heroku时,我在模型中定义的回调没有被使用,甚至不是最简单的回调。所以我来问你,是否有人以前遇到过类似的问题,或者可以帮助我解释我的日志,因为我找不到原因 首先,我的Gemfile是这样的: source 'https://rubygems.org' ruby '2.2.0' group :development, :test do gem 'railroady' end # For do

我一直在使用rails\u admin开发一个学校应用程序。本地的一切都很好,但是当我推到Heroku时,我在模型中定义的回调没有被使用,甚至不是最简单的回调。所以我来问你,是否有人以前遇到过类似的问题,或者可以帮助我解释我的日志,因为我找不到原因

首先,我的Gemfile是这样的:

source 'https://rubygems.org'

ruby '2.2.0'

group :development, :test do
    gem 'railroady'
end

# For documenting models automatically
gem 'annotate', '~> 2.6.6'

# For styling all HTML using SASS
gem 'bourbon'
gem 'neat'
gem 'bitters'

# For using creating SQL triggers inside models
gem 'hairtrigger'

# For creating seed data files from existing data in the database
gem 'seed_dump'

# Used for translations of the mailer and account confirmations
gem 'devise-i18n'

# User permissions and login
gem 'devise'
gem 'cancancan', '~> 1.10'
gem "rolify"
gem "figaro"
gem "rails_admin"

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.1'
# Use sqlite3 as the database for Active Record on the development environment
gem 'sqlite3', group: :development
# Use PostgreSQL as the database for Active Record on the production environment
gem 'pg', group: :production
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.1.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer',  platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0',          group: :doc

# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring', group: :development
gem 'rails_12factor', group: :production
这是我在中使用回调的模型:

region.rb 这就是我在本地服务器上执行相同操作时看到的,正如您所看到的,在POST块中,“key”元素显然是insert查询的参数

Started POST "/admin/region/new" for 127.0.0.1 at 2015-06-02 16:10:18 -0500
Processing by RailsAdmin::MainController#new as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"r8fQgZOsomw4C3P/aL/byEqEIY+BnBAm0WpCdNzYPf+n0v1yENTdUlXE/AfT5JBValjfKVmFubfKIQipxSX1qw==", "region"=>{"name"=>"Prueba"}, "return_to"=>"http://localhost:3000/admin/region", "_save"=>"", "model_name"=>"region"}
  User Load (0.2ms)  SELECT  "users".* FROM "users" WHERE "users"."id" = ?  ORDER BY "users"."id" ASC LIMIT 1  [["id", 1]]
  Role Load (0.2ms)  SELECT "roles".* FROM "roles" INNER JOIN "users_roles" ON "roles"."id" = "users_roles"."role_id" WHERE "users_roles"."user_id" = ? AND (((roles.name = 'super_admin') AND (roles.resource_type IS NULL) AND (roles.resource_id IS NULL)))  [["user_id", 1]]
  Role Load (0.3ms)  SELECT  "roles".* FROM "roles" INNER JOIN "users_roles" ON "roles"."id" = "users_roles"."role_id" WHERE "users_roles"."user_id" = ?  ORDER BY "roles"."id" ASC LIMIT 1  [["user_id", 1]]
   (0.3ms)  begin transaction
  SQL (0.6ms)  INSERT INTO "regions" ("name", "created_at", "updated_at", "key") VALUES (?, ?, ?, ?)  [["name", "Prueba"], ["created_at", "2015-06-02 21:10:18.391401"], ["updated_at", "2015-06-02 21:10:18.391401"], ["key", "Pr"]]
   (150.7ms)  commit transaction
Redirected to http://localhost:3000/admin/region
Completed 302 Found in 175ms (ActiveRecord: 152.2ms)

我发现了错误!它与开发早期在Heroku上的PostgreSQL数据库上直接创建的团队中的其他人的SQL触发器有关,因为它与回调同时被调用,一旦我删除了它,一切都开始按预期工作。

只要生产和本地之间存在差异,我就从基础开始:尝试在Heroku上重新启动应用程序,如果没有差异,请在回调中添加调试语句以查看是否命中:
logger.info“内部回调”
并重新部署。确保两个站点中的代码相同,等等。您在两个环境中使用的数据库是否相同?不,我使用sqlite3进行开发,使用PostgreSQL进行生产,并且我尝试在heroku上重新启动应用程序,但没有成功。不过,我已经解决了这个问题,请看下面的答案。你能再解释一下吗?我现在有这个问题。
# == Schema Information
#
# Table name: teams
#
#  id                   :INTEGER          not null, primary key
#  name                 :varchar
#  key                  :varchar
#  date_of_registration :date
#  company_name         :varchar
#  category_id          :integer
#  address_id           :integer
#  created_at           :datetime         not null
#  updated_at           :datetime         not null
#  winner               :boolean
#

class Team < ActiveRecord::Base
  belongs_to :category, :inverse_of => :teams
  belongs_to :address, :inverse_of => :teams
  has_many :evaluations, :dependent => :destroy, :inverse_of => :team
  has_many :team_members, :dependent => :destroy, :inverse_of => :team
  has_and_belongs_to_many :events

  before_save :generate_key

  def team_label_method
    "#{self.key} - #{self.name}"
  end

  rails_admin do
    object_label_method do
      :team_label_method
    end

    list do
      field :id do
        column_width 40
      end
      field :name do
        column_width 100
      end
      field :key do
        column_width 90
      end
      field :company_name do
        column_width 100
      end
      field :category do
        column_width 70
      end
      field :events do
        column_width 100
      end
      field :winner do
        column_width 10
      end
      field :address do
        column_width 50
      end
    end

    edit do
      field :name do
        required true
        help "Por favor llena este campo."
      end
      #field :key do
      #  required true
      #  help "Por favor llena este campo."
      #end
      field :company_name do
        required true
        help "Por favor llena este campo."
      end
      field :category do
        required true
        help "Por favor llena este campo."
      end
      field :winner do
        default_value = false
        help "Llenar sólo si este equipo es ganador del concurso nacional."
      end
      field :address do
        required true
        help "Por favor llena este campo."
      end
      field :team_members
      field :events do
        required true
        help "Por favor llena este campo."
      end
      field :date_of_registration do
        required true
        help "Por favor llena este campo."
      end
    end
  end

  private
    def generate_key
      standing = "R"
      self.events.each do |current_event|
        if current_event.event_type == "Nacional"
          standing = "N"
        end
      end
      if self.winner == true
        standing = "G"
      end

      region_key = self.events.last.region.key
      year = self.date_of_registration.year
      id = self.id.to_s.rjust(3, '0')
      category = self.category.key
      special = 0

      case self.category.key
        when "S1"
          special = 1
        when "S2"
          special = 2
        when "S3"
          special = 3
        when "S4"
          special = 4
      end

      self.key = "#{standing}#{region_key}#{year}#{id}#{category}#{special}".upcase
    end
end
2015-06-02T21:05:45.566768+00:00 heroku[router]: at=info method=GET path="/admin/region?_pjax=%5Bdata-pjax-container%5D" host=sistema-de-evaluaciones-amte.herokuapp.com request_id=887af50d-bfb8-4a96-889d-e858d980838e fwd="189.241.62.189" dyno=web.1 connect=1ms service=415ms status=200 bytes=11925
2015-06-02T21:05:45.512300+00:00 app[web.1]:   Rendered vendor/bundle/ruby/2.2.0/gems/rails_admin-0.6.7/app/views/rails_admin/main/index.html.haml within layouts/rails_admin/pjax (296.2ms)
2015-06-02T21:05:45.548529+00:00 app[web.1]: Completed 200 OK in 360ms (Views: 321.1ms | ActiveRecord: 22.2ms)
2015-06-02T21:05:47.282570+00:00 heroku[router]: at=info method=GET path="/admin/region/new?_pjax=%5Bdata-pjax-container%5D" host=sistema-de-evaluaciones-amte.herokuapp.com request_id=d8566b9a-943a-4265-afd2-6f339c52c633 fwd="189.241.62.189" dyno=web.1 connect=2ms service=59ms status=200 bytes=3960
2015-06-02T21:05:47.224731+00:00 app[web.1]: Processing by RailsAdmin::MainController#new as HTML
2015-06-02T21:05:47.260190+00:00 app[web.1]:   Rendered vendor/bundle/ruby/2.2.0/gems/rails_admin-0.6.7/app/views/rails_admin/main/_submit_buttons.html.haml (12.7ms)
2015-06-02T21:05:47.224784+00:00 app[web.1]:   Parameters: {"_pjax"=>"[data-pjax-container]", "model_name"=>"region"}
2015-06-02T21:05:47.272787+00:00 app[web.1]: Completed 200 OK in 48ms (Views: 34.2ms | ActiveRecord: 3.7ms)
2015-06-02T21:05:47.245920+00:00 app[web.1]:   Rendered vendor/bundle/ruby/2.2.0/gems/rails_admin-0.6.7/app/views/rails_admin/main/_form_field.html.haml (1.3ms)
2015-06-02T21:05:47.222221+00:00 app[web.1]: Started GET "/admin/region/new?_pjax=%5Bdata-pjax-container%5D" for 189.241.62.189 at 2015-06-02 21:05:47 +0000
2015-06-02T21:05:47.260810+00:00 app[web.1]:   Rendered vendor/bundle/ruby/2.2.0/gems/rails_admin-0.6.7/app/views/rails_admin/main/new.html.haml within layouts/rails_admin/pjax (21.0ms)
2015-06-02T21:05:50.197718+00:00 app[web.1]: Started POST "/admin/region/new" for 189.241.62.189 at 2015-06-02 21:05:50 +0000
2015-06-02T21:05:50.336844+00:00 app[web.1]: Processing by RailsAdmin::MainController#index as HTML
2015-06-02T21:05:50.336854+00:00 app[web.1]:   Parameters: {"model_name"=>"region"}
2015-06-02T21:05:50.447221+00:00 app[web.1]:   Rendered vendor/bundle/ruby/2.2.0/gems/rails_admin-0.6.7/app/views/rails_admin/main/index.html.haml within layouts/rails_admin/application (96.7ms)
2015-06-02T21:05:50.199887+00:00 app[web.1]: Processing by RailsAdmin::MainController#new as HTML
2015-06-02T21:05:50.199969+00:00 app[web.1]:   Parameters: {"utf8"=>"✓", "authenticity_token"=>"jajkJUlQhU2i1z0io6pmDe/NZkzB1kA2hGWL8dYauCb22TYFftstrNop57hKTF2Ye0DxS1SNbZt/WQGoHWn+6w==", "region"=>{"name"=>"Prueba"}, "return_to"=>"https://sistema-de-evaluaciones-amte.herokuapp.com/admin/region", "_save"=>"", "model_name"=>"region"}
2015-06-02T21:05:50.224054+00:00 app[web.1]: Redirected to https://sistema-de-evaluaciones-amte.herokuapp.com/admin/region
2015-06-02T21:05:50.224993+00:00 app[web.1]: Completed 302 Found in 24ms (ActiveRecord: 10.2ms)
2015-06-02T21:05:50.334556+00:00 app[web.1]: Started GET "/admin/region" for 189.241.62.189 at 2015-06-02 21:05:50 +0000
2015-06-02T21:05:50.240345+00:00 heroku[router]: at=info method=POST path="/admin/region/new" host=sistema-de-evaluaciones-amte.herokuapp.com request_id=346211ad-fcf1-4012-9239-3884d01ff0a3 fwd="189.241.62.189" dyno=web.1 connect=1ms service=42ms status=302 bytes=1218
2015-06-02T21:05:50.454815+00:00 app[web.1]:   Rendered vendor/bundle/ruby/2.2.0/gems/rails_admin-0.6.7/app/views/layouts/rails_admin/_navigation.html.haml (5.5ms)
2015-06-02T21:05:50.454724+00:00 app[web.1]:   Rendered vendor/bundle/ruby/2.2.0/gems/rails_admin-0.6.7/app/views/layouts/rails_admin/_secondary_navigation.html.haml (4.9ms)
2015-06-02T21:05:50.485504+00:00 app[web.1]:   Rendered vendor/bundle/ruby/2.2.0/gems/rails_admin-0.6.7/app/views/layouts/rails_admin/pjax.html.haml (10.2ms)
2015-06-02T21:05:50.486076+00:00 app[web.1]: Completed 200 OK in 149ms (Views: 114.7ms | ActiveRecord: 24.4ms)
2015-06-02T21:05:50.502507+00:00 heroku[router]: at=info method=GET path="/admin/region" host=sistema-de-evaluaciones-amte.herokuapp.com request_id=e2439dad-9f8d-407b-b3c8-5229bad08b58 fwd="189.241.62.189" dyno=web.1 connect=6ms service=167ms status=200 bytes=16948
Started POST "/admin/region/new" for 127.0.0.1 at 2015-06-02 16:10:18 -0500
Processing by RailsAdmin::MainController#new as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"r8fQgZOsomw4C3P/aL/byEqEIY+BnBAm0WpCdNzYPf+n0v1yENTdUlXE/AfT5JBValjfKVmFubfKIQipxSX1qw==", "region"=>{"name"=>"Prueba"}, "return_to"=>"http://localhost:3000/admin/region", "_save"=>"", "model_name"=>"region"}
  User Load (0.2ms)  SELECT  "users".* FROM "users" WHERE "users"."id" = ?  ORDER BY "users"."id" ASC LIMIT 1  [["id", 1]]
  Role Load (0.2ms)  SELECT "roles".* FROM "roles" INNER JOIN "users_roles" ON "roles"."id" = "users_roles"."role_id" WHERE "users_roles"."user_id" = ? AND (((roles.name = 'super_admin') AND (roles.resource_type IS NULL) AND (roles.resource_id IS NULL)))  [["user_id", 1]]
  Role Load (0.3ms)  SELECT  "roles".* FROM "roles" INNER JOIN "users_roles" ON "roles"."id" = "users_roles"."role_id" WHERE "users_roles"."user_id" = ?  ORDER BY "roles"."id" ASC LIMIT 1  [["user_id", 1]]
   (0.3ms)  begin transaction
  SQL (0.6ms)  INSERT INTO "regions" ("name", "created_at", "updated_at", "key") VALUES (?, ?, ?, ?)  [["name", "Prueba"], ["created_at", "2015-06-02 21:10:18.391401"], ["updated_at", "2015-06-02 21:10:18.391401"], ["key", "Pr"]]
   (150.7ms)  commit transaction
Redirected to http://localhost:3000/admin/region
Completed 302 Found in 175ms (ActiveRecord: 152.2ms)