強參數我有以下設計的登記表(與不相關的標記省略):困惑與設計
<%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { id: "payment-form" }) do |f| %>
<%= f.fields_for resource.paid_account do |pa| %>
<%= pa.collection_select :account_plan_id, @account_plans, :id, :name_with_price %>
<% end %>
<% end %>
這種形式吐出以下HTML:
<select id="user_paid_account_account_plan_id" name="user[paid_account][account_plan_id]">
<option value="2">Lite ($10.00/mo)</option>
<option value="3">Professional ($20.00/mo)</option>
<option value="4">Plus ($30.00/mo)</option>
</select>
我然後有以下代碼我ApplicationController
:
class ApplicationController < ActionController::Base
before_filter :configure_permitted_parameters, if: :devise_controller?
def configure_permitted_parameters
devise_parameter_sanitizer.for(:sign_up) do |u|
u.permit(
:email,
:password,
:paid_account => :account_plan_id # <-- THIS IS PROBABLY WRONG
)
end
end
end
當我提交我的形式,我得到「PaidAccount( #2163736620)預計,得到ActionController :: Parameters(#2173083140)「。
我也試着不給錯誤的下面,但它也沒有創造一項紀錄:
u.permit(
:email,
:password,
:paid_account => []
)
我在做什麼錯?
我還沒有工作你想的辦法,我只好把消毒的設計這個RegistrationController內,如: '高清sign_up_params params.require(:用戶).permit(:電子郵件,:密碼,:password_confirmation,:current_password,....) end' – sissy