Witam.
Mam problem. Mianowicie ma problem z parsowaniem danych formularza. Oto prosty kod odpalany na ruby 2.3.0 z railsami 4.2.4 Otóż oba słowniki powinny zostać sparsowane tak samo. Tymczasem nie zwraca mi poprawnych danych w drugim przypadku. Ktoś jest mi w stanie powiedzieć dlaczego?
Przepraszam, za kod, ale był on skopiowany z konsoli. <- EDYTKA kod już poprawiony.
require 'rails/all'
# Params passes
_permit = [
"configuration_id",
"max_packages_on_server",
"reports_synch_interval_min",
{
"data_set_users_attributes" => [
{
"0" => [
"user_id",
"send_alerts",
"_destroy"
]
},
{
"2015_09_09_15_21_50" => [
"user_id",
"send_alerts",
"_destroy"
]
}
]
},
{
"data_set_synch_agents_attributes" => [
{
"0" => [
"synch_agent_id",
"max_idle_on_data_set",
"_destroy"
]
},
{
"2015_09_09_15_21_51" => [
"synch_agent_id",
"max_idle_on_data_set",
"_destroy"
]
}
]
}
]
parameters_hash = {
"action" => "create",
"commit" => "Save",
"controller" => "data_sets",
"data_set" => {
"configuration_id" => "",
"data_set_synch_agents_attributes" => {
"0" => {
"_destroy" => "false",
"max_idle_on_data_set" => "-1",
"synch_agent_id" => "1"
},
"2015_09_09_15_21_51" => {
"_destroy" => "",
"max_idle_on_data_set" => "-1",
"synch_agent_id" => "2"
}
},
"data_set_users_attributes" => {
"0" => {
"_destroy" => "false",
"send_alerts" => "1",
"user_id" => "1"
},
"2015_09_09_15_21_50" => {
"_destroy" => "",
"send_alerts" => "1",
"user_id" => "2"
}
},
"max_packages_on_server" => "",
"reports_synch_interval_min" => ""
}
}
params = ActionController::Parameters.new(parameters_hash)
p params.require(:data_set).permit(_permit)
# Params not passes
_permit = [
"configuration_id",
"max_packages_on_server",
"reports_synch_interval_min",
{
"data_set_users_attributes" => [
{
"0" => [
"user_id",
"send_alerts",
"_destroy"
]
},
{
"1" => [
"user_id",
"send_alerts",
"_destroy"
]
}
]
},
{
"data_set_synch_agents_attributes" => [
{
"0" => [
"synch_agent_id",
"max_idle_on_data_set",
"_destroy"
]
},
{
"1" => [
"synch_agent_id",
"max_idle_on_data_set",
"_destroy"
]
}
]
}
]
parameters_hash = {
"action" => "create",
"commit" => "Save",
"controller" => "data_sets",
"data_set" => {
"configuration_id" => "",
"data_set_synch_agents_attributes" => {
"0" => {
"_destroy" => "false",
"max_idle_on_data_set" => "-1",
"synch_agent_id" => "1"
},
"1" => {
"_destroy" => "false",
"max_idle_on_data_set" => "-1",
"synch_agent_id" => "2"
}
},
"data_set_users_attributes" => {
"0" => {
"_destroy" => "false",
"send_alerts" => "1",
"user_id" => "1"
},
"1" => {
"_destroy" => "false",
"send_alerts" => "1",
"user_id" => "2"
}
},
"max_packages_on_server" => "",
"reports_synch_interval_min" => ""
}
}
params = ActionController::Parameters.new(parameters_hash)
p params.require(:data_set).permit(_permit)
Pozdrawiam.