First of all, I want to just get the object inside the current object, which I send to my back-end .
I have this simple JSON (generated from a form):
{ "name": "Project 1", "project_criteria": [ { "name": "Criterium 1", "type": "Type 1", "benefit": "1" }, { "name": "Criterium 2", "type": "Type 2", "benefit": "3" } ] }
My classes :
class Project < ApplicationRecord has_many :project_criteria accepts_nested_attributes_for :project_criteria end class ProjectCriterium < ApplicationRecord belongs_to :project end
ProjectsController:
def project_params params.require(:project).permit(:name, project_criteria: [] ) end
But I still cannot access the project_criteria parameter, as you can see below:
Started POST "/projects" for 127.0.0.1 at 2016-08-19 16:24:03 -0300 Processing by ProjectsController#create as HTML Parameters: {"project"=>{"name"=>"Project 1", "project_criteria"=>{"0"=>{"benefit"=>"1", "name"=>"Criterium 1", "type"=>"Type 1"}, "1"=>{"benefit"=>"3", "name"=>"Criterium 2", "type"=>"Type 2"}}}} Unpermitted parameter: project_criteria # <-----------
Note:
By the way, I already tried to use the criterion instead of the criteria (which , in my opinion, is correct, since it should be pluralized) in has_many and accepts_nested_attributes_for , but it also does not work.
Does anyone have a solution for this?
ruby ruby-on-rails ruby-on-rails-5
developer033
source share