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

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

新規登録して質問してみよう
ただいま回答率
85.50%
CentOS

CentOSは、主にRed Hat Enterprise Linux(RHEL)をベースにした、フリーのソフトウェアオペレーティングシステムです。

Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

MySQL

MySQL(マイエスキューエル)は、TCX DataKonsultAB社などが開発するRDBMS(リレーショナルデータベースの管理システム)です。世界で最も人気の高いシステムで、オープンソースで開発されています。MySQLデータベースサーバは、高速性と信頼性があり、Linux、UNIX、Windowsなどの複数のプラットフォームで動作することができます。

Ruby on Rails

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

Vagrant

Vagrantは、VirtualBox上の仮想マシンを コマンドラインから作成してくれるソフトウェアです。 ビルド環境など容易に構築が可能です。

Q&A

解決済

1回答

1810閲覧

Railsのストロングパラメータのエラーについて教えてください。

koume

総合スコア458

CentOS

CentOSは、主にRed Hat Enterprise Linux(RHEL)をベースにした、フリーのソフトウェアオペレーティングシステムです。

Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

MySQL

MySQL(マイエスキューエル)は、TCX DataKonsultAB社などが開発するRDBMS(リレーショナルデータベースの管理システム)です。世界で最も人気の高いシステムで、オープンソースで開発されています。MySQLデータベースサーバは、高速性と信頼性があり、Linux、UNIX、Windowsなどの複数のプラットフォームで動作することができます。

Ruby on Rails

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

Vagrant

Vagrantは、VirtualBox上の仮想マシンを コマンドラインから作成してくれるソフトウェアです。 ビルド環境など容易に構築が可能です。

0グッド

0クリップ

投稿2017/09/17 14:20

Rails5.1.3でWebアプリケーション制作の勉強中です。たぶんストロングパラメータの所のエラーだと思いますが、
エラーの内容がわからないため自力で解決できないので困っております。
エラーコードは以下になります。

ActionController::ParameterMissing in Customer::AccountsController#update param is missing or the value is empty: home_address Extracted source (around line #65): 63 64 def phone_params(record_name) 65 @params.require(record_name).permit(phones: [ :number, :primary ]) 66 end 67end Rails.root: /home/vagrant/chibi/chibi Application Trace | Framework Trace | Full Trace app/forms/customer/account_form.rb:65:in `phone_params' app/forms/customer/account_form.rb:38:in `assign_attributes' app/controllers/customer/accounts_controller.rb:24:in `update'

コードは以下になります。

app/forms/customer/account_form.rb class Customer::AccountForm include ActiveModel::Model attr_accessor :customer, :inputs_home_address delegate :persisted?, :valid?, :save, to: :customer def initialize(customer) @customer = customer (2 - @customer.personal_phones.size).times do @customer.personal_phones.build end self.inputs_home_address = @customer.home_address.present? @customer.build_home_address unless @customer.home_address (2 - @customer.home_address.phones.size).times do @customer.home_address.phones.build end end def assign_attributes(params = {}) @params = params self.inputs_home_address = params[:inputs_home_address].in? [ '1', 'true' ] customer.assign_attributes(customer_params) phones = phone_params(:customer).fetch(:phones) customer.personal_phones.size.times do |index| attributes = phones[index.to_s] if attributes && attributes[:number].present? customer.personal_phones[index].assign_attributes(attributes) else customer.personal_phones[index].mark_for_destruction end end if inputs_home_address customer.home_address.assign_attributes(home_address_params) phones = phone_params(:home_address).fetch(:phones) 38行目 customer.home_address.phones.size.times do |index| attributes = phones[index.to_s] if attributes && attributes[:number].present? customer.home_address.phones[index].assign_attributes(attributes) else customer.home_address.phones[index].mark_for_destruction end end else customer.home_address.mark_for_destruction end end private def customer_params @params.require(:customer).permit( :family_name, :given_name, :family_name_kana, :given_name_kana, :birthday, :gender, :nickname, :sponsor1 ) end def home_address_params @params.permit(home_address: [:home_address, :postal_code, :prefecture, :city, :address1, :address2]) end def phone_params(record_name) @params.require(record_name).permit(phones: [ :number, :primary ]) ここでエラー発生 65行目 end end
app/controllers/customer/accounts_controller.rb class Customer::AccountsController < Customer::Base def show @customer = current_customer end def edit @customer_form = Customer::AccountForm.new(current_customer) end # PATCH def confirm @customer_form = Customer::AccountForm.new(current_customer) @customer_form.assign_attributes(params[:form]) if @customer_form.valid? render action: 'confirm' else flash.now.alert = '入力に誤りがあります。' render action: 'edit' end end def update @customer_form = Customer::AccountForm.new(current_customer) @customer_form.assign_attributes(params[:form]) 24行目 if params[:commit] if @customer_form.save flash.notice = 'アカウント情報を更新しました。' redirect_to :customer_account else flash.now.alert = '入力に誤りがあります。' render action: 'edit' end else render action: 'edit' end end private def customer_params @params.require(:customer).permit( :family_name, :given_name, :family_name_kana, :given_name_kana, :birthday, :gender, :nickname, :sponsor1 ) end def home_address_params @params.require(:home_address).permit(:home_address, :postal_code, :prefecture, :city, :address1, :address2) end def phone_params(record_name) @params.require(record_name).permit(phones: [ :number, :primary ]) end end

自力で解決できないので、どなたか助けていただけないでしょうか?宜しくお願いします。

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

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

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

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

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

guest

回答1

0

自己解決

不具合点がわからないまま、あっちこっちコードを変えてみてRailsに接続し直したら上手く動いてくれました。???です。

投稿2017/09/18 00:24

koume

総合スコア458

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

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

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.50%

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

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

質問する

関連した質問