前提・実現したいこと
開発環境 :Ruby on Rails 5.2.0
本番環境DB:PostgreSQL
サーバー :Heroku
画像保存先 : aws S3
railsで、投稿アプリを作成しているのですが、どうしても画像の投稿ができません。
(画像以外の投稿はできる)
*ruby初心者のため、的外れなこと言ってたらすんません。
発生している問題・エラーメッセージ
2018-06-26T22:18:47.505109+00:00 app[web.1]: I, [2018-06-26T22:18:47.505027 #4] INFO -- : [d43934a4-9f61-454a-9279-6647d872ab74] Completed 500 Internal Server Error in 5ms (ActiveRecord: 2.0ms) 2018-06-26T22:18:47.505983+00:00 app[web.1]: F, [2018-06-26T22:18:47.505895 #4] FATAL -- : [d43934a4-9f61-454a-9279-6647d872ab74] 2018-06-26T22:18:47.506075+00:00 app[web.1]: F, [2018-06-26T22:18:47.505985 #4] FATAL -- : [d43934a4-9f61-454a-9279-6647d872ab74] ActiveRecord::StatementInvalid (PG::UndefinedTable: ERROR: relation "active_storage_blobs" does not exist 2018-06-26T22:18:47.506079+00:00 app[web.1]: LINE 8: WHERE a.attrelid = '"active_storage_blobs"'::... 2018-06-26T22:18:47.506083+00:00 app[web.1]: ^ 2018-06-26T22:18:47.506085+00:00 app[web.1]: : SELECT a.attname, format_type(a.atttypid, a.atttypmod), 2018-06-26T22:18:47.506086+00:00 app[web.1]: pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod, 2018-06-26T22:18:47.506088+00:00 app[web.1]: c.collname, col_description(a.attrelid, a.attnum) AS comment 2018-06-26T22:18:47.506090+00:00 app[web.1]: FROM pg_attribute a 2018-06-26T22:18:47.506092+00:00 app[web.1]: LEFT JOIN pg_attrdef d ON a.attrelid = d.adrelid AND a.attnum = d.adnum 2018-06-26T22:18:47.506095+00:00 app[web.1]: LEFT JOIN pg_type t ON a.atttypid = t.oid 2018-06-26T22:18:47.506100+00:00 app[web.1]: LEFT JOIN pg_collation c ON a.attcollation = c.oid AND a.attcollation <> t.typcollation 2018-06-26T22:18:47.506102+00:00 app[web.1]: WHERE a.attrelid = '"active_storage_blobs"'::regclass 2018-06-26T22:18:47.506104+00:00 app[web.1]: AND a.attnum > 0 AND NOT a.attisdropped 2018-06-26T22:18:47.506106+00:00 app[web.1]: ORDER BY a.attnum 2018-06-26T22:18:47.506109+00:00 app[web.1]: ):
$ heroku rake db:migrate Running rake db:migrate on ⬢ ilohasu... up, run.7827 (Free) D, [2018-06-26T22:15:30.352252 #4] DEBUG -- : (1.4ms) SELECT pg_try_advisory_lock(6325006434566265) D, [2018-06-26T22:15:30.370865 #4] DEBUG -- : (2.0ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC D, [2018-06-26T22:15:30.389723 #4] DEBUG -- : ActiveRecord::InternalMetadata Load (1.3ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "environment"], ["LIMIT", 1]] D, [2018-06-26T22:15:30.402293 #4] DEBUG -- : (1.1ms) BEGIN D, [2018-06-26T22:15:30.406253 #4] DEBUG -- : (1.2ms) COMMIT D, [2018-06-26T22:15:30.407703 #4] DEBUG -- : (1.1ms) SELECT pg_advisory_unlock(6325006434566265)
下記サイトを参考に進めました
https://qiita.com/hmmrjn/items/479c9e9ce82771f1b6d7
https://www.sejuku.net/blog/8178
該当のソースコード
storage.yml
test: service: Disk root: <%= Rails.root.join("tmp/storage") %> local: service: Disk root: <%= Rails.root.join("storage") %> # Use rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key) amazon: service: S3 access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %> secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %> region: ap-northeast-1 bucket: imuploadtest
database.yml
default: &default adapter: sqlite3 pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> timeout: 5000 development: <<: *default database: db/development.sqlite3 # Warning: The database defined as "test" will be erased and # re-generated from your development database when you run "rake". # Do not set this db to the same as development or production. test: <<: *default database: db/test.sqlite3 production: <<: *default adapter: postgresql encoding: unicode pool: 5
user.rb
class User < ApplicationRecord has_one_attached :image end
_form.html.erb
<%= form_for(@user) do |form| %> <% if user.errors.any? %> <div id="error_explanation"> <h2><%= pluralize(user.errors.count, "error") %> prohibited this user from being saved:</h2> <ul> <% user.errors.full_messages.each do |message| %> <li><%= message %></li> <% end %> </ul> </div> <% end %> <div class="field"> <%= form.label :name %> <%= form.text_field :name %> </div> <div class="field"> <%= form.label :image %> <%= form.file_field :image %> </div> <div class="actions"> <%= form.submit %> </div> <% end %>
show.html.erb
<p id="notice"><%= notice %></p> <p> <strong>Name:</strong> <%= @user.name %> </p> <p> <strong>Image:</strong> <%= image_tag @user.image %> </p> <%= link_to 'Edit', edit_user_path(@user) %> | <%= link_to 'Back', users_path %>
users_controller.erb
class UsersController < ApplicationController before_action :set_user, only: [:show, :edit, :update, :destroy] # GET /users # GET /users.json def index @users = User.all end # GET /users/1 # GET /users/1.json def show end # GET /users/new def new @user = User.new end # GET /users/1/edit def edit end # POST /users # POST /users.json def create @user = User.new(user_params) # x = Cloudinary::Uploader.upload(params[:user][:image]) respond_to do |format| if @user.save format.html { redirect_to @user, notice: 'User was successfully created.' } format.json { render :show, status: :created, location: @user } else format.html { render :new } format.json { render json: @user.errors, status: :unprocessable_entity } end end end # PATCH/PUT /users/1 # PATCH/PUT /users/1.json def update respond_to do |format| if @user.update(user_params) format.html { redirect_to @user, notice: 'User was successfully updated.' } format.json { render :show, status: :ok, location: @user } else format.html { render :edit } format.json { render json: @user.errors, status: :unprocessable_entity } end end end # DELETE /users/1 # DELETE /users/1.json def destroy @user.destroy respond_to do |format| format.html { redirect_to users_url, notice: 'User was successfully destroyed.' } format.json { head :no_content } end end private # Use callbacks to share common setup or constraints between actions. def set_user @user = User.find(params[:id]) end # Never trust parameters from the scary internet, only allow the white list through. def user_params params.require(:user).permit(:name, :image) end end
試したこと
同じようなエラーがあったのですが、自分は解決できずです。
https://teratail.com/questions/77287
https://qiita.com/lotasty66/items/460899c0fd41a7c09304
長々とすみませんが、回答お願いします。
他にも解決のため必要な情報があれば、教えてください。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/06/27 07:50
退会済みユーザー
2018/06/27 08:06
2018/06/27 08:14
退会済みユーザー
2018/06/27 08:42
退会済みユーザー
2018/06/27 08:56
2018/06/27 09:57
退会済みユーザー
2018/06/28 00:13