In a web request, my initial params is like this, without including the unrelated part:
params = {
"base_table"=>{"name"=>"syy", "age"=>"12"},
"tennis_questionaire"=>{"tennis_ball_num"=>"3718"},
"id"=>"1"
}
I want to put the 'base_table' under "tennis_questionaire", because it belongs_to tennis_questionaire, and I want to update the two objects using just one update method. I.e., the end result I want is something like this:
params[:tennis_questionaire] =
{"tennis_ball_num"=>"3718", "base_table"=>{"name"=>"syy", "age"=>"12"}},
In order to achieve this, I created an action_filter to pre-process the params, like this:
before_action :update_param, only: [:create,:update]
def update_param
params[:tennis_questionaire][:base_table] = ActionController::Parameters.new(
params.require(:base_table).permit(:name, :age)
)
end
However, when I was trying to permit it in the actual code of processing the params (the last step before I pass it to update
method):
params.require(:tennis_questionaire).permit(:tennis_ball_num,:base_table)
I found that the :base_table is not permitted.
Why is that so? Any suggestions on how to make it work~?
Thanks a lot