2015-07-03 40 views
0

我目前的項目似乎有登錄/註銷的問題,但僅在生產(返回500錯誤)。當我在開發中本地運行它時,一切都很順利。這些頁面出現,只有當我成功輸入我的登錄信息或嘗試註銷時纔會出現錯誤。我已經通過代碼,查看了heroku日誌等,但我無法解決問題。有些東西讓我覺得它是由於我的郵件程序在環境/開發和生產文件中,但可能不是?Heroku Rails應用程序不允許通過設計登錄/註銷

我一直在檢查整天,無法解決此問題。它昨天工作得很好,我還會補充說我已經嘗試遷移到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 "https://stackoverflow.com/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 

+0

好像你有一個'NoMethodError(未定義的方法'[]」的零:NilClass)''在'app/models/user.rb:9'中。你可以請張貼你的用戶模型(exspecially方法在第9行) – spickermann

+0

我看到了這個,並且仔細檢查了我的模型,我看到他們在說什麼,但是我不明白它的問題。我在另一個項目中有這個確切的代碼,它在那裏工作得很好。感謝您提供的任何幫助,謝謝! =):before_save:http_protocol \t def http_protocol \t除非self.website [/ \ Ahttp:\/\ //] || self.website [/ \ Ahttps:\/\ //] \t self.website = 「HTTP://#{} self.website」 \t年底 \t年底 –

+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 
+0

已成功登錄。 - 謝謝!這是完全合理的,我真的很感激它! =)不幸的是,由於我在這裏的經驗有限,我不能提高你的答案=(我給了它答案,但是再次感謝你!=) –

相關問題