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

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

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

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

Q&A

解決済

1回答

563閲覧

ActionController::ParameterMissingについて

0W5E8fPq1EOm4yE

総合スコア13

Ruby on Rails 6

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

0グッド

0クリップ

投稿2021/01/26 12:34

現在、オリジナルアプリを作成しているのですが、新規投稿をするとパラメータには以下の通りtitle等全然違う情報が含まれていますため、
name,textカラムが保存できません。
本来であれば:name, :text, :youtube_url, :image,:videoが入るはずなのですが、何が原因でしょうか?

Parameters:

{"authenticity_token"=>"[FILTERED]", "article"=>{"title"=>"eqwrghjn", "youtube_url"=>""}, "commit"=>"投稿する"}

イメージ説明

エラー文
param is missing or the value is empty: way

class CreateWays < ActiveRecord::Migration[6.1] def change create_table :ways do |t| t.string :name, null:false t.text :text, null: false t.string :youtube_url t.references :user, null:false, foreign_key: true t.timestamps end end end
class Way < ApplicationRecord belongs_to :user has_one_attached :image has_one_attached :video with_options presence: true do validates :name validates :text end end
class WaysController < ApplicationController before_action :authenticate_user!, except: [:index, :show] before_action :set_way, only: [:show, :edit, :update, :destroy] def index @way = Way.includes(:user).order('created_at DESC') end def new @way = Way.new end def create @way = Way.create!(way_params) binding.pry if @way.save redirect_to ways_path else render :new end end def edit redirect_to action: :index unless @way.user.id == current_user.id end def show end def update if @way.save redirect_to ways_path else render :new end end def destroy if current_user.id == @way.user.id @way.destroy redirect_to :index else render :new end end private def way_params params.require(:name, :text, :youtube_url, :image,:video).merge(user_id: current_user.id) end def set_way @way = Way.find(params[:id]) end end
index.html.erb <div class="container"> <header class="blog-header py-3"> <div class="row flex-nowrap justify-content-between align-items-center"> <div class="col-4 text-center"> <a class="blog-header-logo text-dark" href="/">試験方法 新規投稿</a> </div> </header> <body> <div class=container> <h2>試験方法投稿</h2> <div class='form-wrapper'> <%= form_with model: @way, local: true do |f| %> <div class="field form-group"> <%= f.label :name, "試験名(必須)" %><br /> <%= f.file_field :name, id:"inputFile",class:"form-control" ,type:"text", name:"article[title]", id:"article_title" %> </div> <p> <div class="field form-group"> <label for="article_important_point">説明、方法(必須)</label><br /> <%= f.text_area :text, id:"inputFile",class:"form-control" ,type:"text", name:"article[title]", id:"article_title",rows:"5" %> </div> <p> <div class="field form-group"> <label for="article_youtube_url">参考動画(YouTube)のURL(任意)</label><br /> <%= f.file_field :youtube_url, class:"form-control1", type:"text", name:"article[youtube_url]" ,id:"article_youtube_url",placeholder:"You TubeをURLを入力してください" %> </div> <p> <div class="field"> <label>画像(任意)</label><br /> <%= f.file_field :image, id:"inputFile" %> </div> <p> <div class="field"> <label>動画(任意)</label><br /> <%= f.file_field :video, id:"inputFile" %> </div> <p> <div class="actions text-right"> <%= f.submit "投稿する",class:"btn-default red-round-btn"%> </div> <p> </p> <%=link_to 'キャンセル', ways_path, class:"btn-default cancel-round-btn" %> <% end %> </form></div> </body>

試したこと
userアソシエーションの確認

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

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

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

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

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

guest

回答1

0

自己解決

index.html.erbにある

name:"article[title]"を消したら解決いたしました!

投稿2021/01/26 12:55

0W5E8fPq1EOm4yE

総合スコア13

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

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

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.46%

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

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

質問する

関連した質問