Rails

Migrations are pending. To resolve this issue, run: bin/rails db:migrate RAILS_ENV=development

問題 エラーログさんに言われたように実行 rails db:migrate RAILS_ENV=development 再度起動してもなんもかわらない。。 解決 migrate実行してもなんでエラーが続くのかという根本は解決されてません。 rails g scaffoldもしくはrails g modelで作った時にm…

RailsでBasic認証・Dockerで環境変数を設定

Basic認証の処理を書く class ApplicationController < ActionController::Base before_action :basic_auth protect_from_forgery with: :exception private def basic_auth authenticate_or_request_with_http_basic do |username, password| username == E…

docker上のrailsアプリケーションからローカル上のmysqlに接続できない問題

環境 dockerでrailsを起動 ローカルサーバーでmysqlを起動 問題 すでにrailsはdockerで起動済み railsアプリケーションにアクセスしようとするとdbの接続エラーが出てくる $ curl 0.0.0.0:3000/index Puma caught this error: Can't connect to MySQL server…

rspecの導入

Gemfile group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] # Adds support for Capybara system testing and selenium driver gem '…

Gemfileを編集したらdockerに反映させる

docker-compose build

Docker上の既存DBにアクセスできない問題

問題 railsのアプリケーションから既存のデータベースへ接続したいのに接続できない。(app,db共にdocker上にある) 解決 アプリケーションとDBのdockerのネットワークが違うため。 ネットワークを同じにしなければいけない。 docker-composeファイルでネッ…

rails sでアプリケーションを起動しようとすると、A server is already running.と出てきて起動できない問題

問題 $ rails s A server is already running. Check /app/tmp/pids/server.pid. => Booting Puma => Rails 5.1.6 application starting in development => Run `rails server -h` for more startup options Exiting 別にアプリケーションを起動させてるわけ…

bundleでmysqlをインストールできない問題

問題 $ bundle install The dependency tzinfo-data (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for x86-mingw32, x86-mswin32, x64-mingw32, java. To add tho…

Dockerを起動させてRailsを動かす

Dockerfileを作成 FROM ruby:2.5 RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs RUN mkdir /myapp // 変更 WORKDIR /myapp // 変更 COPY Gemfile /myapp/Gemfile // 変更 COPY Gemfile.lock /myapp/Gemfile.lock // 変更 …

Railsアプリケーション作成、実行

railsのアプリケーション作成 rails _5.1.6_ new hello_world 問題 バージョン指定しているのになぜか勝手にバージョンが5.2.1のrailsになっちゃう 解決方法 mkdir hello_world cd hello_world bundle init vim Gemfile Gemfile source 'https://rubygems.or…