最新版 |
編集中の文章 |
4行目: |
4行目: |
| | | |
| [[rails前バージョン確認|バージョン確認]] | | [[rails前バージョン確認|バージョン確認]] |
− |
| |
− | [https://help.onamae.com/contact/ お名前.com問い合わせ]
| |
| | | |
| == create application == | | == create application == |
19行目: |
17行目: |
| | | |
| % bin/setup | | % bin/setup |
− |
| |
− | サーバー側
| |
− | $ bundle install --without test development
| |
− |
| |
− | database.yml username:などを確認する (2箇所)
| |
− | <nowiki># /config/database.yml
| |
− |
| |
− | production:
| |
− | <<: *default
| |
− | database: tabetai_production
| |
− | username: jq
| |
− | password: <%= ENV["TABETAI_DATABASE_PASSWORD"] %></nowiki>
| |
− |
| |
− | <nowiki># /config/environments/production.rb
| |
− |
| |
− | config.assets.compile = true
| |
− |
| |
− | config.action_mailer.raise_delivery_errors = true
| |
− | config.action_mailer.delivery_method = :smtp
| |
− | #host = 'localhost'
| |
− | host = 'http://onk.pokpok.jp'
| |
− | config.action_mailer.default_url_options = { host: host }</nowiki>
| |
− |
| |
− | データベース作成
| |
− | $ createdb tabetai_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>
| |
| | | |
| == テスト用のデータで開発用のデータをつくる設定 == | | == テスト用のデータで開発用のデータをつくる設定 == |
73行目: |
23行目: |
| puts "\n== Seeding the database with fixtures ==" | | puts "\n== Seeding the database with fixtures ==" |
| system("bin/rails db:fixtures:load")</nowiki> | | 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 == | | == user == |
− | % bundle exec rails g model User email:string
| |
− |
| |
− | t.string :email, null: false, index: { unique: true }
| |
− |
| |
− | % bundle exec rails db:migrate
| |
− |
| |
− | <nowiki># app/models/user.rb
| |
− |
| |
− | validates :email, presence: true, uniqueness: true</nowiki>
| |
− |
| |
− | == home ==
| |
− | ホームを作る
| |
− | % rails generate controller Pages home
| |
− |
| |
− | homeコントローラーはパブリックなので、認証をはずす
| |
− | <nowiki># app/controllers/pages_controller.rb
| |
− |
| |
− | skip_before_action :authenticate_user!
| |
− | </nowiki>
| |
− |
| |
− | ルートパス
| |
− | <nowiki># config/routes.rb
| |
− |
| |
− | root to: "pages#home"</nowiki>
| |
− |
| |
− |
| |
− | == user devise ==
| |
| % bin/rails generate devise:install | | % bin/rails generate devise:install |
| | | |
162行目: |
69行目: |
| | | |
| Modelを作成 | | Modelを作成 |
− | $ bin/rails generate devise User | + | $ rails g devise User |
− | $ bin/rails db:migrate | + | $ rails db:migrate |
− | | |
− | Viewを作成
| |
− | $ rails generate devise:views users
| |
− | | |
− | view更新
| |
− | <nowiki># config/initializers/devise.rb
| |
− | | |
− | config.scoped_views = true</nowiki>
| |
− | | |
− | | |
− | ログインしないとアクセスできないようにする
| |
− | <nowiki># app/controllers/application_controller.rb
| |
− | | |
− | class ApplicationController < ActionController::Base
| |
− | before_action :authenticate_user!, unless: :devise_controller?
| |
− | end</nowiki>
| |
− | | |
− | == DeviseとOmniauthでGoogle、Twitter、Facebook認証 ==
| |
− | | |
− | gem 'dotenv-rails'
| |
− | $ bundle install
| |
− | $ touch .env
| |
− | | |
− | <nowiki>HOST='example.jp'
| |
− | TWITTER_API_KEY=
| |
− | TWITTER_API_SECRET=
| |
− | GOOGLE_CLIENT_ID=
| |
− | GOOGLE_CLIENT_SECRET=
| |
− | FACEBOOK_KEY=
| |
− | FACEBOOK_SECRET=</nowiki>
| |
− | | |
− | <nowiki>gem 'omniauth-facebook'
| |
− | gem 'omniauth-twitter'
| |
− | gem 'omniauth-google-oauth2'</nowiki>
| |
− | | |
− | [[oauth|bundle install後のメッセージ]]
| |
− | | |
− | $ 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
| |