在heroku上使用活动管理员保存记录不起作用

时间:2014-05-25 17:36:36

标签: ruby-on-rails heroku activeadmin

我在我的rails应用中使用active_admin。当我尝试为PostCategory模型添加新记录时,它无法正常工作。

我可以在Heroku上添加其他模型,但只有PostCategory不起作用。 在我的本地计算机上,可以添加所有模型,包括PostCategory

有时日志文件会显示500内部错误。

我的heroku记录:

2014-05-25T17:27:30.946410+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.0/lib/active_support/callbacks.rb:82:in `run_callbacks'
2014-05-25T17:27:30.946411+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/activemodel-4.1.0/lib/active_model/validations/callbacks.rb:111:in `run_validations!'
2014-05-25T17:27:30.946413+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/activemodel-4.1.0/lib/active_model/validations.rb:317:in `valid?'
2014-05-25T17:27:30.946414+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.0/lib/active_record/validations.rb:70:in `valid?'
2014-05-25T17:27:30.946416+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.0/lib/active_record/validations.rb:77:in `perform_validations'
2014-05-25T17:27:30.946417+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.0/lib/active_record/validations.rb:51:in `save'
2014-05-25T17:27:30.946464+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/actionpack-4.1.0/lib/abstract_controller/callbacks.rb:20:in `block in process_action'
2014-05-25T17:27:30.946418+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.0/lib/active_record/attribute_methods/dirty.rb:21:in `save'
2014-05-25T17:27:30.946420+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.0/lib/active_record/transactions.rb:268:in `block (2 levels) in save'
2014-05-25T17:27:30.946435+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.0/lib/active_record/transactions.rb:267:in `save'
2014-05-25T17:27:30.946437+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/bundler/gems/active_admin-ad33a0f6c772/lib/active_admin/resource_controller/data_access.rb:160:in `block in save_resource'
2014-05-25T17:27:30.946439+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.0/lib/active_support/core_ext/object/try.rb:45:in `call'
2014-05-25T17:27:30.946440+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.0/lib/active_support/core_ext/object/try.rb:45:in `public_send'
2014-05-25T17:27:30.946441+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.0/lib/active_support/core_ext/object/try.rb:45:in `try'
2014-05-25T17:27:30.946446+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/bundler/gems/active_admin-ad33a0f6c772/lib/active_admin/callbacks.rb:79:in `block (2 levels) in define_active_admin_callbacks'
2014-05-25T17:27:30.946470+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.0/lib/active_support/callbacks.rb:166:in `call'
2014-05-25T17:27:30.946448+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/bundler/gems/active_admin-ad33a0f6c772/lib/active_admin/resource_controller/data_access.rb:159:in `save_resource'
2014-05-25T17:27:30.946472+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.0/lib/active_support/callbacks.rb:166:in `call'
2014-05-25T17:27:30.946422+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.0/lib/active_record/transactions.rb:329:in `block in with_transaction_returning_status'
2014-05-25T17:27:30.946450+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/bundler/gems/active_admin-ad33a0f6c772/lib/active_admin/resource_controller/data_access.rb:149:in `block in create_resource'
2014-05-25T17:27:30.946474+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.0/lib/active_support/callbacks.rb:166:in `block in halting'
2014-05-25T17:27:30.946475+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.0/lib/active_support/callbacks.rb:229:in `call'
2014-05-25T17:27:30.946476+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.0/lib/active_support/callbacks.rb:229:in `block in halting'
2014-05-25T17:27:30.946478+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.0/lib/active_support/callbacks.rb:229:in `call'
2014-05-25T17:27:30.946463+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/actionpack-4.1.0/lib/action_controller/metal/rendering.rb:10:in `process_action'
2014-05-25T17:27:30.946461+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/actionpack-4.1.0/lib/abstract_controller/base.rb:189:in `process_action'
2014-05-25T17:27:30.946466+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.0/lib/active_support/callbacks.rb:113:in `call'
2014-05-25T17:27:30.946467+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.0/lib/active_support/callbacks.rb:113:in `call'
2014-05-25T17:27:30.946468+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.0/lib/active_support/callbacks.rb:166:in `block in halting'
2014-05-25T17:27:30.946471+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.0/lib/active_support/callbacks.rb:166:in `block in halting'
2014-05-25T17:27:30.946479+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.0/lib/active_support/callbacks.rb:229:in `block in halting'
2014-05-25T17:27:30.946480+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.0/lib/active_support/callbacks.rb:166:in `call'
2014-05-25T17:27:30.946484+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.0/lib/active_support/callbacks.rb:166:in `block in halting'
2014-05-25T17:27:30.946482+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.0/lib/active_support/callbacks.rb:166:in `block in halting'
2014-05-25T17:27:30.946487+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.0/lib/active_support/callbacks.rb:166:in `block in halting'
2014-05-25T17:27:30.946489+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.0/lib/active_support/callbacks.rb:86:in `call'
2014-05-25T17:27:30.946483+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.0/lib/active_support/callbacks.rb:166:in `call'
2014-05-25T17:27:30.946486+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.0/lib/active_support/callbacks.rb:166:in `call'
2014-05-25T17:27:30.946493+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/actionpack-4.1.0/lib/action_controller/metal/rescue.rb:29:in `process_action'
2014-05-25T17:27:30.946490+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.0/lib/active_support/callbacks.rb:86:in `run_callbacks'
2014-05-25T17:27:30.946492+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/actionpack-4.1.0/lib/abstract_controller/callbacks.rb:19:in `process_action'
2014-05-25T17:27:30.946495+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/actionpack-4.1.0/lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'
2014-05-25T17:27:30.946511+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/actionpack-4.1.0/lib/action_controller/metal.rb:195:in `dispatch'
2014-05-25T17:27:30.946512+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/actionpack-4.1.0/lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
2014-05-25T17:27:30.946514+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/actionpack-4.1.0/lib/action_controller/metal.rb:231:in `block in action'
2014-05-25T17:27:30.946515+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/actionpack-4.1.0/lib/action_dispatch/routing/route_set.rb:80:in `call'
2014-05-25T17:27:30.946507+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.0/lib/active_record/railties/controller_runtime.rb:18:in `process_action'
2014-05-25T17:27:30.946496+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.0/lib/active_support/notifications.rb:159:in `block in instrument'
2014-05-25T17:27:30.946500+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.0/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
2014-05-25T17:27:30.946502+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.0/lib/active_support/notifications.rb:159:in `instrument'
2014-05-25T17:27:30.946503+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/actionpack-4.1.0/lib/action_controller/metal/instrumentation.rb:30:in `process_action'
2014-05-25T17:27:30.946505+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/actionpack-4.1.0/lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
2014-05-25T17:27:30.946508+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/actionpack-4.1.0/lib/abstract_controller/base.rb:136:in `process'
2014-05-25T17:27:30.946510+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/actionview-4.1.0/lib/action_view/rendering.rb:30:in `process'
2014-05-25T17:27:30.946517+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/actionpack-4.1.0/lib/action_dispatch/routing/route_set.rb:80:in `dispatch'
2014-05-25T17:27:30.946518+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/actionpack-4.1.0/lib/action_dispatch/routing/route_set.rb:48:in `call'
2014-05-25T17:27:30.946520+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/actionpack-4.1.0/lib/action_dispatch/journey/router.rb:71:in `block in call'
2014-05-25T17:27:30.946521+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/actionpack-4.1.0/lib/action_dispatch/journey/router.rb:59:in `each'
2014-05-25T17:27:30.946523+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/actionpack-4.1.0/lib/action_dispatch/journey/router.rb:59:in `call'
2014-05-25T17:27:30.946524+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/actionpack-4.1.0/lib/action_dispatch/routing/route_set.rb:676:in `call'
2014-05-25T17:27:30.946525+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/warden-1.2.3/lib/warden/manager.rb:35:in `block in call'
2014-05-25T17:27:30.946527+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/warden-1.2.3/lib/warden/manager.rb:34:in `catch'
2014-05-25T17:27:30.946528+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/warden-1.2.3/lib/warden/manager.rb:34:in `call'
2014-05-25T17:27:30.946530+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/etag.rb:23:in `call'
2014-05-25T17:27:30.946532+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/conditionalget.rb:35:in `call'
2014-05-25T17:27:30.946533+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/head.rb:11:in `call'
2014-05-25T17:27:30.946534+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/actionpack-4.1.0/lib/action_dispatch/middleware/params_parser.rb:27:in `call'
2014-05-25T17:27:30.946536+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/actionpack-4.1.0/lib/action_dispatch/middleware/flash.rb:254:in `call'
2014-05-25T17:27:30.946537+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/session/abstract/id.rb:225:in `context'
2014-05-25T17:27:30.946549+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/actionpack-4.1.0/lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
2014-05-25T17:27:30.946539+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/session/abstract/id.rb:220:in `call'
2014-05-25T17:27:30.946540+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/actionpack-4.1.0/lib/action_dispatch/middleware/cookies.rb:560:in `call'
2014-05-25T17:27:30.946542+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.0/lib/active_record/query_cache.rb:36:in `call'
2014-05-25T17:27:30.946543+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/activerecord-4.1.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:621:in `call'
2014-05-25T17:27:30.946545+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/actionpack-4.1.0/lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
2014-05-25T17:27:30.946546+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.0/lib/active_support/callbacks.rb:82:in `run_callbacks'
2014-05-25T17:27:30.946548+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/actionpack-4.1.0/lib/action_dispatch/middleware/callbacks.rb:27:in `call'
2014-05-25T17:27:30.946550+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/actionpack-4.1.0/lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
2014-05-25T17:27:30.946551+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/actionpack-4.1.0/lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
2014-05-25T17:27:30.946553+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/railties-4.1.0/lib/rails/rack/logger.rb:38:in `call_app'
2014-05-25T17:27:30.946554+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/railties-4.1.0/lib/rails/rack/logger.rb:20:in `block in call'
2014-05-25T17:27:30.946556+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.0/lib/active_support/tagged_logging.rb:68:in `block in tagged'
2014-05-25T17:27:30.946557+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.0/lib/active_support/tagged_logging.rb:26:in `tagged'
2014-05-25T17:27:30.946562+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.0/lib/active_support/tagged_logging.rb:68:in `tagged'
2014-05-25T17:27:30.946586+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/railties-4.1.0/lib/rails/rack/logger.rb:20:in `call'
2014-05-25T17:27:30.946587+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/actionpack-4.1.0/lib/action_dispatch/middleware/request_id.rb:21:in `call'
2014-05-25T17:27:30.946590+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/runtime.rb:17:in `call'
2014-05-25T17:27:30.946589+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/methodoverride.rb:21:in `call'
2014-05-25T17:27:30.946591+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/activesupport-4.1.0/lib/active_support/cache/strategy/local_cache_middleware.rb:26:in `call'
2014-05-25T17:27:30.946593+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/actionpack-4.1.0/lib/action_dispatch/middleware/static.rb:64:in `call'
2014-05-25T17:27:30.946594+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/sendfile.rb:112:in `call'
2014-05-25T17:27:30.946595+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/railties-4.1.0/lib/rails/engine.rb:514:in `call'
2014-05-25T17:27:30.946597+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/railties-4.1.0/lib/rails/application.rb:144:in `call'
2014-05-25T17:27:30.946599+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/lock.rb:17:in `call'
2014-05-25T17:27:30.946600+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/content_length.rb:14:in `call'
2014-05-25T17:27:30.946602+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/handler/webrick.rb:60:in `service'
2014-05-25T17:27:30.946603+00:00 app[web.1]:   vendor/ruby-2.0.0/lib/ruby/2.0.0/webrick/httpserver.rb:138:in `service'
2014-05-25T17:27:30.946605+00:00 app[web.1]:   vendor/ruby-2.0.0/lib/ruby/2.0.0/webrick/httpserver.rb:94:in `run'
2014-05-25T17:27:30.946606+00:00 app[web.1]:   vendor/ruby-2.0.0/lib/ruby/2.0.0/webrick/server.rb:295:in `block in start_thread'
2014-05-25T17:27:30.946618+00:00 app[web.1]:
2014-05-25T17:27:30.946619+00:00 app[web.1]:

宝石文件

gem 'rails', '4.1.0'
# Use sqlite3 as the database for Active Record
gem 'sqlite3', group: :development
# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.3'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.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 'activeadmin', github: 'gregbell/active_admin'

gem 'devise'

gem 'rails_12factor', group: :production

gem 'pg', group: :production

gem 'debugger'

gem 'pry', group: :development

post_category.rb:

ActiveAdmin.register PostCategory do
  permit_params :title

  index do
    selectable_column
    id_column
    column :title
    column :created_at
    column :slug_url

    actions
  end

  filter :created_at


  form do |f|
    f.inputs "PostCategory Details" do
      f.input :title
    end
    f.actions
  end

    controller do
        defaults :finder => :find_by_slug_url
    end

end

在heroku控制台上查看PostCategory

PostCategory(id: integer, title: string, created_at: datetime, updated_at: datetime, slug_url: string)

PostCategory模型:

class PostCategory < ActiveRecord::Base
    validates_uniqueness_of :slug_url
    before_save :before_save

    private
    def before_save
        self.slug_url = self.title.downcase.strip.gsub(' ', '-').gsub(/[^\w-]/, '')
    end

    public 
    def to_param  # overridden
        slug_url
    end
end

1 个答案:

答案 0 :(得分:1)

所以你有很多问题:

  1. def before_save更改为其他内容这是rails方法在尝试使用downcase之前,不要使用相同的名称也验证标题不为空/ nil(存在?)你会得到错误(nil:nilClass的未定义方法downcase)

  2. 我认为您第一次尝试它时,如果您将查询,您将看到您的数据库包含1条记录,如果您尝试再次提交它,由于您的验证validates_uniqueness_of :slug_url <将无效/ p>