2

Ruby On Rails と Devise を使用してアプリを作成しています。ユーザー モデルと管理者モデルを作成しました。アプリをローカルで実行すると問題なく動作しますが、heroku で実行すると問題が発生します。問題は、新しい管理者を作成しようとすると、「申し訳ありませんが、問題が発生しました」というエラー メッセージが表示されることです。私はすでに rake db:migrate と heroku run 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にリンクしていませんが、代わりに未定義のメソッドとして表示されている「name」属性を読み取っているdevise/registrations/new.html.erbにリンクしていますエラー。

私の 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

私が得ることができる助けをいただければ幸いです!初めてアプリを作成するので、質問がばかげている場合は申し訳ありませんが、行き詰まっており、助けが必要です!

4

1 に答える 1

0

最初に gitrepo をチェックして、ファイルまたは関連ファイルが何らかの理由で無視されていることを確認します。

それが問題でない場合は、heroku プロジェクトを破棄して最初からやり直してください。

Heroku には、新しいリポジトリ/プロジェクトが正しく作成されない場合がある特別な方法があります。失敗率はかなり低いですが、スネークアイを転がしただけかもしれません。

それでもうまくいかない場合は、production.rb と development.rb を投稿してください。

于 2013-04-08T20:22:04.167 に答える