Webアプリケーション制作の勉強中です。ストロングパラメータのエラーが出たのでストロングパラメータの記述をし、リロードするとActionController::ParameterMissing in Staff::CustomersController#indexのエラーが出てしまいどうすればいいのでしょうか?
解決策がわからず困っております。どなたか教えていただけないでしょうか?お願いします。
最初のコード
app/controllers/staff/customers_controller.rb class Staff::CustomersController < Staff::Base def index @search_form = Staff::CustomerSearchForm.new(params[:search]) @customers = @search_form.search.page(params[:page]) end def show @customer = Customer.find(params[:id]) end def new @customer_form = Staff::CustomerForm.new end def edit @customer_form = Staff::CustomerForm.new(Customer.find(params[:id])) end def create @customer_form = Staff::CustomerForm.new @customer_form.assign_attributes(params[:form]) if @customer_form.save flash.notice = '顧客を追加しました。' redirect_to action: 'index' else flash.now.alert = '入力に誤りがあります。' render action: 'new' end end def update @customer_form = Staff::CustomerForm.new(Customer.find(params[:id])) @customer_form.assign_attributes(params[:form]) if @customer_form.save flash.notice = '顧客情報を更新しました。' redirect_to action: 'index' else flash.now.alert = '入力に誤りがあります。' render action: 'edit' end end def destroy customer = Customer.find(params[:id]) customer.destroy! flash.notice = '顧客アカウントを削除しました。' redirect_to :staff_customers end end ```ここでForbiddenAttributes Erroeが出たのでストロングパラメータに関するコードを追記。 ```ここに言語を入力 class Staff::CustomersController < Staff::Base def index @search_form = Staff::CustomerSearchForm.new(customer_params) @customers = @search_form.search.page(params[:page]) end ・ ・ ・ private def customer_params params.require(:customer).permit( :family_name_kana, :given_name_kana, :birth_year, :birth_month, :birth_mday, :address_type, :prefecture, :city, :phone_number ) end
ここでリロードすると以下のエラーが出てしまいます。
ActionController::ParameterMissing in Staff::CustomersController#index param is missing or the value is empty: customer Extracted source (around line #52): 50 private 51 def customer_params 52 params.require(:customer).permit( 53 :family_name_kana, :given_name_kana, 54 :birth_year, :birth_month, :birth_mday, 55 :address_type, :prefecture, Rails.root: /home/vagrant/chibi/chibi Application Trace | Framework Trace | Full Trace app/controllers/staff/customers_controller.rb:52:in `customer_params' app/controllers/staff/customers_controller.rb:3:in `index' Request Parameters: {"host"=>"chibi.example.com"}
単純なミスだとは思いますが自己解決できなくて困っております。どなたか教えていただけないでしょうか?
宜しくお願いします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/08/21 14:52