Heroku Rails应用程序不允许通过Devise登录/注销

时间:2015-07-03 22:39:59

标签: ruby-on-rails ruby ruby-on-rails-4 heroku devise

我目前的项目似乎遇到了登录/注销问题,但仅限于生产(返回500错误)。当我在开发中本地运行时,一切都顺利进行。页面出现,只有在我成功输入登录信息或尝试注销后才会出现错误。我已经通过代码,查看了heroku日志等,但我无法解决问题。有些东西让我觉得它是由于我的邮件环境/开发和生产文件,但也许不是吗?

我一整天都在检查,无法解决这个问题。它昨天工作得非常好,我还要补充说我已经尝试迁移到heroku但仍然没有。这只会返回:ActiveRecord::SchemaMigration Load (2.8ms) SELECT "schema_migrations".* FROM "schema_migrations"。这就是我的文件:

环境/开发:

Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.

# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the web server when you make code changes.
config.cache_classes = false

# Do not eager load code on boot.
config.eager_load = false

# Show full error reports and disable caching.
config.consider_all_requests_local       = true
config.action_controller.perform_caching = false

# Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = true

# Print deprecation notices to the Rails logger.
config.active_support.deprecation = :log

# Raise an error on page load if there are pending migrations.
config.active_record.migration_error = :page_load

# Debug mode disables concatenation and preprocessing of assets.
# This option may cause significant delays in view rendering with a large
# number of complex assets.
config.assets.debug = true

# Asset digests allow you to set far-future HTTP expiration dates on all assets,
# yet still be able to expire them through the digest params.
config.assets.digest = true

# Adds additional error checking when serving assets at runtime.
# Checks for improperly declared sprockets dependencies.
# Raises helpful error messages.
config.assets.raise_runtime_errors = true

# Raises error for missing translations
# config.action_view.raise_on_missing_translations = true

config.action_mailer.default_url_options = { :host => 'localhost:3000' }

end

环境/生产:

Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.

# Code is not reloaded between requests.
config.cache_classes = true

# Eager load code on boot. This eager loads most of Rails and
# your application in memory, allowing both threaded web servers
# and those relying on copy on write to perform better.
# Rake tasks automatically ignore this option for performance.
config.eager_load = true

# Full error reports are disabled and caching is turned on.
config.consider_all_requests_local       = false
config.action_controller.perform_caching = true

# Enable Rack::Cache to put a simple HTTP cache in front of your application
# Add `rack-cache` to your Gemfile before enabling this.
# For large-scale production use, consider using a caching reverse proxy like
# NGINX, varnish or squid.
# config.action_dispatch.rack_cache = true

# Disable serving static files from the `/public` folder by default since
# Apache or NGINX already handles this.
config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present?

# Compress JavaScripts and CSS.
config.assets.js_compressor = :uglifier
# config.assets.css_compressor = :sass

# Do not fallback to assets pipeline if a precompiled asset is missed.
config.assets.compile = false

# Asset digests allow you to set far-future HTTP expiration dates on all assets,
# yet still be able to expire them through the digest params.
config.assets.digest = true

# `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb

# Specifies the header that your server uses for sending files.
# config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX

# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
# config.force_ssl = true

# Use the lowest log level to ensure availability of diagnostic information
# when problems arise.
config.log_level = :debug

# Prepend all log lines with the following tags.
# config.log_tags = [ :subdomain, :uuid ]

# Use a different logger for distributed setups.
# config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)

# Use a different cache store in production.
# config.cache_store = :mem_cache_store

# Enable serving of images, stylesheets, and JavaScripts from an asset server.
# config.action_controller.asset_host = 'http://assets.example.com'

# Ignore bad email addresses and do not raise email delivery errors.
# Set this to true and configure the email server for immediate delivery to raise delivery errors.
# config.action_mailer.raise_delivery_errors = false

# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
# the I18n.default_locale when a translation cannot be found).
config.i18n.fallbacks = true

# Send deprecation notices to registered listeners.
config.active_support.deprecation = :notify

# Use default logging formatter so that PID and timestamp are not suppressed.
config.log_formatter = ::Logger::Formatter.new

# Do not dump schema after migrations.
config.active_record.dump_schema_after_migration = false

config.action_mailer.default_url_options = { :host => 'programinperson.com' }

end

这似乎是heroku日志返回的内容:

2015-07-03T21:43:20.852266+00:00 heroku[router]: at=info method=GET path="/assets/application-c650ec08eab8760c43c795f72c49b7876951ab1ba6a11806a2ce7a63fbf31209.js" host=www.programinperson.com request_id=d3e04089-0dff-4f53-a8d6-eaf8b4808240 fwd="98.160.140.78" dyno=web.1 connect=2ms service=6ms status=304 bytes=133
2015-07-03T21:43:22.284984+00:00 app[web.1]:    (0.5ms)  BEGIN
2015-07-03T21:43:22.286082+00:00 app[web.1]: Completed 500 Internal Server Error in 4ms (ActiveRecord: 1.8ms)
2015-07-03T21:43:22.280157+00:00 app[web.1]: Started DELETE "/users/sign_out" for 98.160.140.78 at 2015-07-03 21:43:22 +0000
2015-07-03T21:43:22.281680+00:00 app[web.1]: Processing by Devise::SessionsController#destroy as HTML
2015-07-03T21:43:22.281686+00:00 app[web.1]:   Parameters: {"authenticity_token"=>"oHbV6VtpWAST1t5oYMJVFaPKyIVSZkP2kIsFYTT/DsYzTErySqJH0ZKIGeKBBCE6WVTxmgW4psPQAuF1nw1IdQ=="}
2015-07-03T21:43:22.283543+00:00 app[web.1]:   User Load (0.7ms)  SELECT  "users".* FROM "users" WHERE "users"."id" = $1  ORDER BY "users"."id" ASC LIMIT 1  [["id", 1]]
2015-07-03T21:43:22.287538+00:00 app[web.1]: 
2015-07-03T21:43:22.285770+00:00 app[web.1]:    (0.6ms)  ROLLBACK
2015-07-03T21:43:22.287540+00:00 app[web.1]: NoMethodError (undefined method `[]' for nil:NilClass):
2015-07-03T21:43:22.287561+00:00 app[web.1]: 
2015-07-03T21:43:22.287560+00:00 app[web.1]:   app/models/user.rb:9:in `http_protocol'
2015-07-03T21:43:22.287562+00:00 app[web.1]: 

您可以提供的任何信息都会非常感激!我只是卡住了,不确定从哪里开始。非常感谢你。

编辑:这就是我的模型在第9行:

before_save :http_protocol

def http_protocol
  unless self.website[/\Ahttp:\/\//] || self.website[/\Ahttps:\/\//]
    self.website = "http://#{self.website}"
  end
end

1 个答案:

答案 0 :(得分:2)

您之前的保存过滤器http_protocol尝试将用户的website与正则表达式匹配:

self.website[/\Ahttp:\/\//]

根据您的日志文件失败,因为websitenil

要避免此问题,您需要首先检查website是否存在,请将该方法更改为以下内容:

def http_protocol 
  if website.present?
    self.website = "http://#{self.website}" unless website[/\Ahttps?:\/\//]
  end
end