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

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

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

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

Q&A

0回答

523閲覧

[rails]編集ページにて画像ファイルの更新ができない

YutoKubo

総合スコア13

Ruby on Rails 6

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

0グッド

0クリップ

投稿2020/12/14 02:49

画像ファイルの更新されず、編集画面にて画像を変更しても、投稿時に反映されません。
ご指摘よろしくお願いします。
<_form.html.erb>

<section> <div class="container"> <div class="co_post_form"> <%= form_for @community do |f| %> <div class="col"> <div class="field"> <%= f.label :title%> <%= f.text_field :title %> </div> <div class="body"> <%= f.label :introduction ,class:"introduction"%> <%= f.text_area :introduction ,class:"introduction" %> </div> <div class="image"> <%= f.label :intro_image %> <%= f.attachment_field :intro_image %> </div> <%= f.submit '投稿', class:"btn btn-primary btn-lg"%> </div> <%end%> </div> </div> </section>

<communities.controller.rb>

class CommunitiesController < ApplicationController before_action :set_community, only: [:edit, :show, :update] def new @community = Community.new end def create @community = current_user.communities.build(community_params)#ストロングパラメータを呼び出す if @community.save redirect_to communities_path(@community), notice: "投稿に成功しました。" else render :new end end def edit if @community.user_id != current_user.id redirect_to communities_path, alert: '不正なアクセスです。' end @community = Community.find(params[:id]) end def index @communities = Community.all end def show end def update if @community.update(community_params) redirect_to communities_path(@community), notice: "投稿に成功しました。" else render :edit end end def destroy community = Community.find(params[:id]) community.destroy redirect_to communities_path end private def community_params params.require(:community).permit(:title, :introduction, :intro_image) end def set_community @community = Community.find(params[:id]) end end

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

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

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

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

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

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

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

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

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問