I am passing variable like that:
new_sub_request_path(request_id:@request.id)
so i get this url:
http://localhost:3000/sub_requests/new?request_id=1
In my controller i want to assign that request_id like that:
@sub_request = SubRequest.new(sub_request_params)
@sub_request.request_id = params[:request_id]
and my strong parameters are defined:
def sub_request_params
params.require(:sub_request).permit(:description, :diagnos, :price, :payment, :request_id)
end
But after save i have empty request_id attribute, so it seems that it is not assigned. What am I doing wrong?
EDIT: Inspecting parameters in the console showed that i only have those attributes that are in my form.
EDIT2:
def create
@sub_request = SubRequest.new(sub_request_params)
@sub_request.request_id = params[:sub_request][:request_id]
respond_to do |format|
if @sub_request.save
format.html { redirect_to @sub_request, notice: 'Sub request was successfully created.' }
format.json { render :show, status: :created, location: @sub_request }
else
format.html { render :new }
format.json { render json: @sub_request.errors, status: :unprocessable_entity }
end
end
end
@sub_request.request_id = params[:sub_request][:request_id]Request?