我正在使用rails的主动管理员,并在创建屏幕上为属于父母的模型工作。我收到一个unpermitted_param错误,因为activeadmin会自动将父ID添加到要提交的表单参数中。但是,参数是在模型的哈希之外添加的。以下是提交的参数:
{ “UTF8”=> “中✓”, “authenticity_token”=> “中9MBGkptu3jjLd4Zoy6lLUe1r6hW9TwRAmmiUNz2SwvQapRYv8nvOqZKWZKhgn9TEIXwNiD + IheQERVs + DpUgfA ==”, “wedding_cake”=> {“client_id”=>“1”,“first_name”=>“bob”, “last_name”=>“smith”,“address”=>“11大圈”, “city”=>“boston”,“state”=>“ma”,“zip”=>“01234”, “phone”=>“1234567890”,“email”=>“”,“来宾”=>“150”, “time”=>“12:30 pm”,“special_instructions”=>“”,“package”=>“湖景 pavillion“,”flower_price“=>”0“,”rolled_chocolate_price“=>”0“, “other_price”=>“0”,“tiering_price”=>“0”,“存款”=>“50”, “balance”=>“150”,“vendor_balance”=>“0”,“delivery_price”=>“0”, “顾问”=>“彼得”,“日期(1i)”=>“2019”,“日期(2i)”=>“11”, “date(3i)”=>“18”,“slice_price”=>“3.50”, “appointment_date(1i)”=>“2018”,“appointment_date(2i)”=>“10”, “appointment_date(3i)”=>“16”},“commit”=>“创建结婚蛋糕”, “CLIENT_ID”=> “中1”}
wedding_cake属于客户端,应该有一个client_id(它可以)。但是,正如您所看到的,在wedding_cake之外还有另一个client_id。这是我用来生成表单的代码:
form do |f|
inputs 'Venue Info' do
f.input :client_id, :as => :hidden, :input_html => { :value => f.object.client_id }
f.input :first_name
f.input :last_name
f.input :address
f.input :city
f.input :state
f.input :zip
f.input :phone
f.input :email
end
inputs 'Cake Info' do
f.input :guests
f.input :time
f.input :special_instructions
f.input :package
f.input :flower_price
f.input :rolled_chocolate_price
f.input :other_price
f.input :tiering_price
f.input :deposit
f.input :balance
f.input :vendor_balance
f.input :delivery_price
f.input :consultant
f.input :date
f.input :slice_price
f.input :appointment_date
end
f.submit
end
我的strong_parameters设置如下:
我在我的activeadmin注册中设置了allowed_params:permit_params :client_id, :base_price, :first_name, :last_name, :address, :city, :state, :zip, :phone, :email, :guests, :time, :special_instructions, :package, :flower_price, :rolled_chocolate_price, :other_price, :tiering_price, :deposit, :balance, :vendor_balance, :delivery_price, :consultant, :date, :slice_price, :appointment_date