質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.51%
Devise

Deviseとは、Ruby-on-Railsの認証機能を追加するプラグインです。

Heroku

HerokuはHeroku社が開発と運営を行っているPaaSの名称です。RubyやNode.js、Python、そしてJVMベース(Java、Scala、Clojureなど)の複数のプログラミング言語をサポートしている。

Ruby on Rails 4

Ruby on Rails4はRubyによって書かれたオープンソースのウェブフレームワークです。 Ruby on Railsは「設定より規約」の原則に従っており、効率的に作業を行うために再開発を行う必要をなくしてくれます。

Q&A

解決済

1回答

2698閲覧

Heroku上でのdeviseの動作

kensukesuke

総合スコア19

Devise

Deviseとは、Ruby-on-Railsの認証機能を追加するプラグインです。

Heroku

HerokuはHeroku社が開発と運営を行っているPaaSの名称です。RubyやNode.js、Python、そしてJVMベース(Java、Scala、Clojureなど)の複数のプログラミング言語をサポートしている。

Ruby on Rails 4

Ruby on Rails4はRubyによって書かれたオープンソースのウェブフレームワークです。 Ruby on Railsは「設定より規約」の原則に従っており、効率的に作業を行うために再開発を行う必要をなくしてくれます。

1グッド

0クリップ

投稿2016/08/28 17:51

こんばんは。

Ruby のgem "devise"を使い、ログイン機能を実装したアプリケーションを開発しています。
サインインした場合、開発環境ではうまくサインインできるのですが、Herokuにアップした本番環境だとサインインしてもサインインページに再び遷移してしまい、サインインできません。

どのようにすると、Heroku上でもサインインすることができるでしょうか?

ruby

1#development.rb 2 3Rails.application.configure do 4 # Settings specified here will take precedence over those in config/application.rb. 5 6 # In the development environment your application's code is reloaded on 7 # every request. This slows down response time but is perfect for development 8 # since you don't have to restart the web server when you make code changes. 9 config.cache_classes = false 10 11 # Do not eager load code on boot. 12 config.eager_load = false 13 14 # Show full error reports and disable caching. 15 config.consider_all_requests_local = true 16 config.action_controller.perform_caching = false 17 18 # Don't care if the mailer can't send. 19 config.action_mailer.raise_delivery_errors = true 20 21 # Print deprecation notices to the Rails logger. 22 config.active_support.deprecation = :log 23 24 # Raise an error on page load if there are pending migrations. 25 config.active_record.migration_error = :page_load 26 27 # Debug mode disables concatenation and preprocessing of assets. 28 # This option may cause significant delays in view rendering with a large 29 # number of complex assets. 30 config.assets.debug = true 31 32 # Asset digests allow you to set far-future HTTP expiration dates on all assets, 33 # yet still be able to expire them through the digest params. 34 config.assets.digest = true 35 36 # Adds additional error checking when serving assets at runtime. 37 # Checks for improperly declared sprockets dependencies. 38 # Raises helpful error messages. 39 config.assets.raise_runtime_errors = true 40 config.action_mailer.default_url_options = { host: 'localhost', port: 3000 } 41 config.action_mailer.smtp_settings = { 42 :enable_starttls_auto => true, 43 :address => "smtp.gmail.com", 44 :port => 587, 45 :domain => 'smtp.gmail.com', 46 :user_name => "xxxxxx@gmail.com", #gmailアドレス 47 :password => "省略", #gmailパスワード 48 :authentication => 'login', 49} 50 # Raises error for missing translations 51 # config.action_view.raise_on_missing_translations = true 52end 53

ruby

1#production.rb 2Rails.application.configure do 3 # Settings specified here will take precedence over those in config/application.rb. 4 # Code is not reloaded between requests. 5 config.cache_classes = true 6 # Eager load code on boot. This eager loads most of Rails and 7 # your application in memory, allowing both threaded web servers 8 # and those relying on copy on write to perform better. 9 # Rake tasks automatically ignore this option for performance. 10 config.eager_load = true 11 12 # Full error reports are disabled and caching is turned on. 13 config.consider_all_requests_local = false 14 config.action_controller.perform_caching = true 15 16 # Enable Rack::Cache to put a simple HTTP cache in front of your application 17 # Add `rack-cache` to your Gemfile before enabling this. 18 # For large-scale production use, consider using a caching reverse proxy like 19 # NGINX, varnish or squid. 20 # config.action_dispatch.rack_cache = true 21 22 # Disable serving static files from the `/public` folder by default since 23 # Apache or NGINX already handles this. 24 config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present? 25 26 # Compress JavaScripts and CSS. 27 config.assets.js_compressor = :uglifier 28 # config.assets.css_compressor = :sass 29 30 # Do not fallback to assets pipeline if a precompiled asset is missed. 31 config.assets.compile = true 32 33 # Asset digests allow you to set far-future HTTP expiration dates on all assets, 34 # yet still be able to expire them through the digest params. 35 config.assets.digest = true 36 config.action_mailer.default_url_options = { :host => 'xxx.herokuapp.com' } 37 config.action_mailer.smtp_settings = { 38 :enable_starttls_auto => true, 39 :address => "smtp.gmail.com", 40 :port => 587, 41 :domain => 'smtp.gmail.com', 42 :user_name => "xxxx", #gmailアドレス 43 :password => "省略", #gmailパスワード 44 :authentication => 'login', 45} 46 # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb 47 48 # Specifies the header that your server uses for sending files. 49 # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache 50 # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX 51 52 # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. 53 # config.force_ssl = true 54 55 # Use the lowest log level to ensure availability of diagnostic information 56 # when problems arise. 57 config.log_level = :debug 58 59 # Prepend all log lines with the following tags. 60 # config.log_tags = [ :subdomain, :uuid ] 61 62 # Use a different logger for distributed setups. 63 # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new) 64 65 # Use a different cache store in production. 66 # config.cache_store = :mem_cache_store 67 68 # Enable serving of images, stylesheets, and JavaScripts from an asset server. 69 # config.action_controller.asset_host = 'http://assets.example.com' 70 71 # Ignore bad email addresses and do not raise email delivery errors. 72 # Set this to true and configure the email server for immediate delivery to raise delivery errors. 73 # config.action_mailer.raise_delivery_errors = false 74 75 # Enable locale fallbacks for I18n (makes lookups for any locale fall back to 76 # the I18n.default_locale when a translation cannot be found). 77 config.i18n.fallbacks = true 78 79 # Send deprecation notices to registered listeners. 80 config.active_support.deprecation = :notify 81 82 # Use default logging formatter so that PID and timestamp are not suppressed. 83 config.log_formatter = ::Logger::Formatter.new 84 config.assets.css_compressor = :yui 85 # Do not dump schema after migrations. 86 config.active_record.dump_schema_after_migration = false 87end 88 89

ruby

1#routes.rb 2 3Rails.application.routes.draw do 4 5 devise_for :users, controllers: { registrations: 'registrations', passwords: 'passwords', sessions: 'sessions'} 6 resources :project do 7 member do 8 get 'setting' 9 end 10 collection do 11 get 'top' 12 get 'how' 13 get 'email' 14 get 'questions' 15 end 16 resources :sheet do 17 member do 18 get 'all' 19 end 20 collection do 21 get 'did' 22 get 'print' 23 end 24 end 25 resources :member 26end 27 28 root 'project#top' 29 # The priority is based upon order of creation: first created -> highest priority. 30 # See how all your routes lay out with "rake routes". 31 32 # You can have the root of your site routed with "root" 33 # root 'welcome#index' 34 35 # Example of regular route: 36 # get 'products/:id' => 'catalog#view' 37 38 # Example of named route that can be invoked with purchase_url(id: product.id) 39 # get 'products/:id/purchase' => 'catalog#purchase', as: :purchase 40 41 # Example resource route (maps HTTP verbs to controller actions automatically): 42 # resources :products 43 44 # Example resource route with options: 45 # resources :products do 46 # member do 47 # get 'short' 48 # post 'toggle' 49 # end 50 # 51 # collection do 52 # get 'sold' 53 # end 54 # end 55 56 # Example resource route with sub-resources: 57 # resources :products do 58 # resources :comments, :sales 59 # resource :seller 60 # end 61 62 # Example resource route with more complex sub-resources: 63 # resources :products do 64 # resources :comments 65 # resources :sales do 66 # get 'recent', on: :collection 67 # end 68 # end 69 70 # Example resource route with concerns: 71 # concern :toggleable do 72 # post 'toggle' 73 # end 74 # resources :posts, concerns: :toggleable 75 # resources :photos, concerns: :toggleable 76 77 # Example resource route within a namespace: 78 # namespace :admin do 79 # # Directs /admin/products/* to Admin::ProductsController 80 # # (app/controllers/admin/products_controller.rb) 81 # resources :products 82 # end 83end 84 85```ruby

#application_controller.rb

class ApplicationController < ActionController::Base

before_filter :basic

private
def basic
authenticate_or_request_with_http_basic do |user, pass|
user == 'xxxx' && pass == 'xxxxx'
end
end

def after_sign_in_path_for(resource)
'/project'
end

def after_sign_out_path_for(resource)
'/project/top'
end

def after_sign_up_path_for(resource)
'/project'
end

def after_inactive_sign_up_path_for(resource)
'/project'
end

Prevent CSRF attacks by raising an exception.

For APIs, you may want to use :null_session instead.

protect_from_forgery with: :exception
end

サインイン後に"/project"に遷移するようにしたいと考えています。 バージョンはrails4を使用しています。 プログラミング初心者で、汚いコードで申し訳ありませんがよろしくお願いいたします。
退会済みユーザー👍を押しています

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

こんにちは。僕もrails書き始めて日も浅くましてherokuはまだ使ったことがないので不確かなのですが、調べてみてもしかしたらと思ったことがあったので書きました。

Ruby

1#config/application 2config.assets.initialize_on_precompile = false

どうやら上記のような設定が必要なようです。

もしよかったら試してみてください。

一応この記述が必要であることを確認したのがQiitaなので(僕が書いたわけではありませんが。。)URLをつけておきます。

HerokuでDeviseを使用する手順 on Rails3.2.13, ruby1.9.3, Sendgrid

素人が探したものなので的確なものかわかりませんが、頑張ってください!

投稿2016/08/30 13:11

neko_53

総合スコア75

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.51%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問