質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.46%
Ruby on Rails 6

Ruby on Rails 6は、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Q&A

0回答

118閲覧

file_fieldで作成したボタンを押しても反応がなく、画像を選択できない

takuyahori

総合スコア0

Ruby on Rails 6

Ruby on Rails 6は、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

0グッド

0クリップ

投稿2021/11/05 14:34

解決したいこと

Ruby on railsで画像投稿アプリを作成しています。
Active strageを用いた画像投稿機能を実装しており、必要な記述は記載して
画像を選択するボタンをクリックしても画像が選択できないという事象が
起きています。
解決方法を教えていただきたいです。

発生している問題・エラー

5998737B-BA04-47CE-B9F3-E5277833C378_1_105_c.jpeg

カーソルの当たっているボタンを押しても何も反応がありません。

該当するソースコード

routes.rb

1Rails.application.routes.draw do 2 devise_for :cliants, controllers: { 3 sessions: 'cliants/sessions', 4 passwords: 'cliants/passwords', 5 registrations: 'cliants/registrations' 6 } 7 devise_for :trainers, controllers: { 8 sessions: 'trainers/sessions', 9 passwords: 'trainers/passwords', 10 registrations: 'trainers/registrations' 11 } 12 root to: 'posts#index' 13 resources :posts, only: [:new, :create] 14end

posts_controller.rb

1class PostsController < ApplicationController 2 def index 3 end 4 5 def new 6 @post = Post.new 7 end 8 9 def create 10 @post = Post.new(post_params) 11 if @post.save 12 redirect_to root_path 13 else 14 render :new 15 end 16 end 17 18 private 19 20 def post_params 21 params.require(:post).permit(:title, :today, :explanation, :image).merge(cliant_id: current_cliant.id) 22 end 23end

post.rb

1class Post < ApplicationRecord 2 belongs_to :cliant 3 has_one_attached :image 4 5 with_options presence: true do 6 validates :title 7 validates :today 8 validates :explanation 9 validates :image 10 end 11end

_form.html.erb

1<%= form_with model: @post, local: true do |f| %> 2 <div class="field"> 3 <%= f.label :title, "タイトル" %><br /> 4 <%= f.text_field :title, id: "posts_title" %> 5 </div> 6 7 <div class="field"> 8 <%= f.label :date, "投稿日" %><br /> 9 <%= f.date_select :date, id: "posts_date" %> 10 </div> 11 12 <div class="field"> 13 <%= f.label :explanation, "説明文" %><br /> 14 <%= f.text_area :explanation, class: :form_text, id: "posts_explanation" %> 15 </div> 16 17 <div class="field"> 18 <%= f.label :image, "食事写真" %><br /> 19 <%= f.file_field :image , id:"posts_image" %> 20 </div> 21 22 <div class="actions"> 23 <%= f.submit "保存する", class: :form_btn %> 24 </div> 25<% end %>

20211102122551_create_active_storage_tables.active_storage.rb

1# This migration comes from active_storage (originally 20170806125915) 2class CreateActiveStorageTables < ActiveRecord::Migration[5.2] 3 def change 4 create_table :active_storage_blobs do |t| 5 t.string :key, null: false 6 t.string :filename, null: false 7 t.string :content_type 8 t.text :metadata 9 t.bigint :byte_size, null: false 10 t.string :checksum, null: false 11 t.datetime :created_at, null: false 12 13 t.index [ :key ], unique: true 14 end 15 16 create_table :active_storage_attachments do |t| 17 t.string :name, null: false 18 t.references :record, null: false, polymorphic: true, index: false 19 t.references :blob, null: false 20 21 t.datetime :created_at, null: false 22 23 t.index [ :record_type, :record_id, :name, :blob_id ], name: "index_active_storage_attachments_uniqueness", unique: true 24 t.foreign_key :active_storage_blobs, column: :blob_id 25 end 26 end 27end

自分で試したこと

・ActiveStorageやmini-magick等gemのインストールがうまくいってないのでは
・ActiveStorageの導入に必要な記述の誤字などがないか
等思いつくことは試してみましたがうまくいかず、どなたかお力をお貸し
いただきたいです、、、
宜しくお願いいたします。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

neko_daisuki

2021/11/11 23:50

画像が表示されません。 ブラウザの開発者ツールのコンソールにエラーは出ていませんか?
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.46%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問