以下のコードのようにcreateアクション内で2つのインスタンス変数を使えるようにしたいのですが、うまくいきません。
class DesignsController < ApplicationController def new @design = Design.new @content = Design.new end def create @design = Design.new(design_params) MailSenderDesign.inquiry(@design).deliver respond_to do |format| if @design.save format.html {render action: 'create'} else format.html {render action: 'new'} end end content = {} upload_file = content_params[:upload_file] if upload_file != nil content[:upload_file] = upload_file.read content = content_params[:upload_file_name] end @content = Design.new(content) respond_to do |format| if @content.save format.html { redirect_to :action => "new", notice: 'Upload success' } else @contents = Content.all format.html { render action: 'index' } end end end private def design_params params.require(:design).permit(:company, :name, :email, :url,:option1, :option2, :option3, :option4, :option5, :option6, :material, :processing, :analysis, :other) end def content_params params.require(:content).permit(:upload_file) end end コード
@designではdesignに関するパラメーターを取得し、
@contentにはファイルアップローダー機能を与えてあります。
どちらか一方だけでの実行ならうまくいくのですが、2つのインスタンス変数をcreateアクション内で定義するとこのようなエラーが出てしまいます。
ActionController::ParameterMissing at /designs param is missing or the value is empty: content コード
contentのキーに対してバリューが結びついていない、もしくは書き方自体に問題があると思うのですが、わかるかたがいましたらお願い致します。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。