差分

Tabetai

1,568 バイト追加, 2023年7月14日 (金) 11:06
DeviseとOmniauthでGoogle、Twitter、Facebook認証
production:
<<: *default
database: koresore_productiontabetai_production
username: jq
password: <%= ENV["KORESORE_DATABASE_PASSWORDTABETAI_DATABASE_PASSWORD"] %></nowiki>
<nowiki># /config/environments/production.rb
config.action_mailer.delivery_method = :smtp
#host = 'localhost'
host = 'http://koresoreonk.pokpok.jp'
config.action_mailer.default_url_options = { host: host }</nowiki>
データベース作成
$ createdb koresore_productiontabetai_production
$ rails db:migrate RAILS_ENV=production
 
== production ==
% $ DISABLE_DATABASE_ENVIRONMENT_CHECK=1 rails db:drop RAILS_ENV=production
 
<nowiki>本番環境でbin/devを実行する。
 
RAILS_ENV環境変数を設定して本番環境を指定。
 
export RAILS_ENV=production
 
bundleコマンドを使用してGemの依存関係をインストール。
 
bundle install
 
プリコンパイルされたアセットを生成。
 
bundle exec rails assets:precompile
 
サーバーを起動。
 
bundle exec rails server</nowiki>
== テスト用のデータで開発用のデータをつくる設定 ==
puts "\n== Seeding the database with fixtures =="
system("bin/rails db:fixtures:load")</nowiki>
 
== db:rollback ==
% rails db:migrate:status
 
% rails db:rollback
 
% rails db:rollback STEP=n
 
% rails db:migrate:down VERSION=**************
 
== gemのアンインストール方法 ==
<nowiki>$ bundle exec gem uninstall <gem名>
 
Gemfileから該当のgemの行を削除
 
$ bundle install</nowiki>
== user ==
$ rails g migration AddOmniauthToUsers provider:string uid:string
 
<nowiki># config/initializers/devise.rb
 
config.omniauth :facebook, ENV['FACEBOOK_KEY'], ENV['FACEBOOK_SECRET'], scope: 'email', info_fields: 'email', callback_url: "#{ENV['HOST']}/users/auth/facebook/callback"
 
config.omniauth :twitter, ENV['TWITTER_API_KEY'], ENV['TWITTER_API_SECRET'], scope: 'email', oauth_callback: "#{ENV['HOST']}/users/auth/twitter/callback"
 
config.omniauth :google_oauth2, ENV['GOOGLE_CLIENT_ID'], ENV['GOOGLE_CLIENT_SECRET'], scope: 'email', redirect_uri: "#{ENV['HOST']}/users/auth/google_oauth2/callback"
 
OmniAuth.config.logger = Rails.logger if Rails.env.development?</nowiki>
 
<nowiki>$ mkdir app/controllers/users/
$ touch app/controllers/users/omniauth_callbacks_controller.rb</nowiki>
 
== test ==
~/tabetai2$ bin/rails generate simple_form:install