Expensive!
I'm having a hard time because I'm new to Rails.
I'm trying to generate a form with two templates through Nested Form Rails. It's a simple template.
"Engine" has one or more "parts", and "part" has only one "motor". This way I made the models:
class Motor < ActiveRecord::Base
has_many :pecas
accepts_nested_attributes_for :pecas
end
class Peca < ActiveRecord::Base
belongs_to :motor
end
The motors controller is:
def new
@motor = Motor.new
end
def create
@motor = Motor.new(motor_params)
@motor.pecas.build(params[:id])
respond_to do |format|
if @motor.save
format.html { redirect_to @motor, notice: 'Motor was successfully created.' }
format.json { render action: 'show', status: :created, location: @motor }
else
format.html { render action: 'new' }
format.json { render json: @motor.errors, status: :unprocessable_entity }
end
end
end
private
def set_motor
@motor = Motor.find(params[:id])
end
def motor_params
params.require(:motor).permit(:nome, {:peca_attributes => [:item]})
end
Everything works perfectly (ALMOST). "Engine" has an attribute that is name: string and Peca has an attribute called item: string.
I am able to generate a record of parts when I record a "engine" through the modified "engine" view but I CAN NOT RECORD THE NAME OF THE "ITEM" ATTRIBUTE NAME OF THE "PECA" MODEL.
I think it's a new STRONG PARAMETERS guideline in rails 4. Can anyone help me?
Thank you!