after the community an i solved my problem rails how to use Associated Model with the admin namespace i get the data from the form into the controller, my def create
crashed.
I'm using rails 5.1.5 with ruby 2.5.0. I have two models the model A and Model B.
Model A has_many bs
Model B belongs_to a
The Controller with the crash is
app/controllers/admin/bs_controller.rb
class Admin::BsController < ApplicationController
def create
@a = A.find(params[:a_id])
@b = @a.bs.create(entry_params)
redirect_to a_path(@a)
end
NoMethodError in Admin::BsController#create
undefined method `bs' for nil:NilClass
def create
@a = A.find(params[:a_id])
**@b = @a.bs.create(entry_params)**
redirect_to a_path(@a)
end
Is it correct? First i have to find the "A-Entry" from is main Model, the i can create the new entry which belongs_to a?