LoginSignup
0
0

More than 1 year has passed since last update.

railsアプリ作成の忘却録

Last updated at Posted at 2021-09-27

webアプリケーションの新規作成

$rails new アプリ名(その後にオプションの指定)
$rails new アプリ名 --datebase=postgrep --api 

PostgreSQL
データベース(SQL)の1つ
オープンソース、データベースと関連付けた
丈夫さ、パフォーマンス性に特徴がある
インストール方法とか使い方の記述が豊富

データベーステーブルを作成した際のエラー

$ bundle exec rails db:create
$ bundle exec rails db:migrate

を記述したら

could not connect to server: No such file or directory
    Is the server running locally and accepting
    connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
Couldn't create 'scaffold_app_development' database. Please check your configuration.
rails aborted!
ActiveRecord::ConnectionNotEstablished: could not connect to server: No such file or directory
    Is the server running locally and accepting
    connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
/Users/▲▲/dev/rails/scaffold_app/bin/rails:5:in `<top (required)>'
/Users/▲▲/dev/rails/scaffold_app/bin/spring:10:in `block in <top (required)>'
/Users/▲▲/dev/rails/scaffold_app/bin/spring:7:in `tap'
/Users/▲▲/dev/rails/scaffold_app/bin/spring:7:in `<top (required)>'

Caused by:
PG::ConnectionBad: could not connect to server: No such file or directory
    Is the server running locally and accepting
    connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
/Users/▲▲/dev/rails/scaffold_app/bin/rails:5:in `<top (required)>'
/Users/▲▲/dev/rails/scaffold_app/bin/spring:10:in `block in <top (required)>'
/Users/▲▲/dev/rails/scaffold_app/bin/spring:7:in `tap'
/Users/▲▲/dev/rails/scaffold_app/bin/spring:7:in `<top (required)>'
Tasks: TOP => db:create
(See full trace by running task with --trace)

のようにエラーが発生

postgreSQLを再起動したら解決しました。

$brew services restart postgresql
Created database '●●_development'
Created database '●●_test'

rakeタスクファイルの作成

$bundle exec rails g task scheduler

成功

create  lib/tasks/scheduler.rake

herokuへのデプロイ時のエラー

remote:  !     Could not detect rake tasks
remote:  !     ensure you can run `$ bundle exec rake -P` against your app
remote:  !     and using the production group of your Gemfile.
remote:  !     rake aborted!
remote:  !     SyntaxError: scheduler.rake:2: syntax error, unexpected tIDENTIFIER, expecting end-of-input
remote:  !     task :update_ feed => :environment do

このようなエラーが発生した
解読したところscheduler.rakeの2行目
task :update_ feed => :environment doに問題があると表示された

2行目を確認したところ

task :update_ feed => :environment do

update_ feedの間に空白があったので埋めたら
無事うまくいった

エラー文がどれだけ優秀か悟った

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0