3,728
回編集
差分
Tabetai
,→DeviseとOmniauthでGoogle、Twitter、Facebook認証
[[rails前バージョン確認|バージョン確認]]
[https://help.onamae.com/contact/ お名前.com問い合わせ]
== create application ==
% 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>
== テスト用のデータで開発用のデータをつくる設定 ==
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 ==
% 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
Viewを作成