我正在使用Ruby On Rails和Devise创建一个应用程序。我已经创建了一个用户模型和一个管理员模型,当我在本地运行它时,我的应用程序工作正常,但是当我在heroku上运行时,我遇到了问题。麻烦的是,当我尝试创建一个新的管理员时,我显示了一条错误消息,上面写着“我们很抱歉,但出了点问题。”我已经完成了rake db:migrate和heroku运行rake db:migrate。当我查看heroku日志时,我看到了:
2013-04-08T19:34:49+00:00 app[web.1]: Started GET "/admins/sign_up" for 98.154.183.5 at 2013-04-08 19:34:49 +0000
2013-04-08T19:34:49+00:00 app[web.1]: Processing by Admins::RegistrationsController#new as HTML
2013-04-08T19:34:50+00:00 app[web.1]: Rendered devise/registrations/new.html.erb within layouts/application (431.3ms)
2013-04-08T19:34:50+00:00 app[web.1]: ActionView::Template::Error (undefined method `name' for #<Admin:0x00000005207678>):
2013-04-08T19:34:50+00:00 app[web.1]: Completed 500 Internal Server Error in 549ms
2013-04-08T19:34:50+00:00 app[web.1]:
2013-04-08T19:34:50+00:00 app[web.1]: 3: <%= simple_form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { class: 'form-horizontal'}) do |f| %>
2013-04-08T19:34:50+00:00 app[web.1]: 4: <%= f.error_notification %>
2013-04-08T19:34:50+00:00 app[web.1]: 5:
2013-04-08T19:34:50+00:00 app[web.1]: 6: <%= f.input :name %>
2013-04-08T19:34:50+00:00 app[web.1]: 8: <%= f.input :password %>
2013-04-08T19:34:50+00:00 app[web.1]: app/views/devise/registrations/new.html.erb:6:in `block in _app_views_devise_registrations_new_html_erb___3397140481100313441_30072880'
2013-04-08T19:34:50+00:00 app[web.1]: app/views/devise/registrations/new.html.erb:3:in `_app_views_devise_registrations_new_html_erb___3397140481100313441_30072880'
2013-04-08T19:34:50+00:00 app[web.1]: 7: <%= f.input :email %>
2013-04-08T19:34:50+00:00 app[web.1]: 9: <%= f.input :password_confirmation %>
2013-04-08T19:34:50+00:00 app[web.1]:
2013-04-08T19:34:50+00:00 app[web.1]:
2013-04-08T19:34:50+00:00 heroku[router]: at=info method=GET path=/admins/sign_up host=protected-cliffs-2228.herokuapp.com fwd="98.154.183.5" dyno=web.1 connect=1ms service=559ms status=500 bytes=643
由于某些原因我不知道heroku没有链接到admins / registrations / new.html.erb,而是链接到devise / registrations / new.html.erb,它正在读取显示为的'name'属性未定义的方法错误。
我的controllers / admins / registrations_controller.rb文件如下所示:
class Admins::RegistrationsController < Devise::RegistrationsController
end
我的routes.rb文件如下所示:
MyFirstApp::Application.routes.draw do
get "users/show"
devise_for :admins, :controllers => { :registrations => "admins/registrations", :sessions => "admins/sessions" } do
get "/admins/sign_up" => "admins/registrations#new"
get "/admins/sign_in" => "admins/sessions#new"
end
resources :posts
devise_for :users
match 'users/:id' => 'users#show'
root :to => 'pages#home'
get 'about' => 'pages#about'
end
我的development.rb文件
MyFirstApp::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
# Log error messages when you accidentally call methods on nil.
config.whiny_nils = true
# 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 = false
# Print deprecation notices to the Rails logger
config.active_support.deprecation = :log
# Only use best-standards-support built into browsers
config.action_dispatch.best_standards_support = :builtin
# Raise exception on mass assignment protection for Active Record models
config.active_record.mass_assignment_sanitizer = :strict
# Log the query plan for queries taking more than this (works
# with SQLite, MySQL, and PostgreSQL)
config.active_record.auto_explain_threshold_in_seconds = 0.5
# Do not compress assets
config.assets.compress = false
# Expands the lines which load the assets
config.assets.debug = true
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
end
我的production.rb文件
MyFirstApp::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
# Full error reports are disabled and caching is turned on
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
# Disable Rails's static asset server (Apache or nginx will already do this)
config.serve_static_assets = false
# Compress JavaScripts and CSS
config.assets.compress = true
# Don't fallback to assets pipeline if a precompiled asset is missed
config.assets.compile = false
# Generate digests for assets URLs
config.assets.digest = true
# Defaults to nil and saved in location specified by config.assets.prefix
# config.assets.manifest = YOUR_PATH
# 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
# See everything in the log (default is :info)
# 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"
# Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
# config.assets.precompile += %w( search.js )
# Disable delivery errors, bad email addresses will be ignored
# config.action_mailer.raise_delivery_errors = false
# Enable threaded mode
# config.threadsafe!
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
# the I18n.default_locale when a translation can not be found)
config.i18n.fallbacks = true
# Send deprecation notices to registered listeners
config.active_support.deprecation = :notify
# Log the query plan for queries taking more than this (works
# with SQLite, MySQL, and PostgreSQL)
# config.active_record.auto_explain_threshold_in_seconds = 0.5
#In production, :host should be set to the actual host of your application.
config.action_mailer.default_url_options = { :host => 'myfirstapp.heroku.com' }
#Configuring Amazon S3 for Paperclip file uploads
config.paperclip_defaults = {
:storage => :s3,
:s3_credentials => {
:bucket => ENV['AWS_BUCKET'],
:access_key_id => ENV['AWS_ACCESS_KEY_ID'],
:secret_access_key => ENV['AWS_SECRET_ACCESS_KEY']
}
}
end
我的.gitignore文件
# See http://help.github.com/ignore-files/ for more about ignoring files.
#
# If you find yourself ignoring temporary files generated by your text editor
# or operating system, you probably want to add a global ignore instead:
# git config --global core.excludesfile ~/.gitignore_global
# Ignore bundler config
/.bundle
# Ignore the default SQLite database.
/db/*.sqlite3
# Ignore all logfiles and tempfiles.
/log/*.log
/tmp
doc/
*.swp
*~
.project
.DS_Store
.idea
# Ignore Paperclip unloaded files
/public/system
我很感激我能得到任何帮助!这是我第一次创建一个应用程序,所以如果我的问题很愚蠢但是我被困住了,我需要一些帮助,我很抱歉!
答案 0 :(得分:0)
首先检查你的gitrepo以确保文件或相关文件由于某种原因被忽略。
如果那不是问题那么只需要修改heroku项目并重新开始。
Heroku有一种特殊的方式,有时不能正确创建新的repos /项目。失败率非常小,但你可能只是卷起蛇眼。
如果这不起作用,请发布您的production.rb和development.rb。