Hello Ryan,
this tutorial saved my life since I am absolutly a newbie with ruby and rails and this article is exactly what I need for my project! But unfortanely there are two things I can't explain to myself:
First, in your example you put a first task into the project when creating a new one
@project.tasks.build # creates just one task
but this one never appears in my project. Even if I would try something like
10.times {@voucher.positions.build}there is still no task ('position' in my case) until I add the first one. Do you (or anybody else) have an idea what the problem could be?
The second problem is that error which occurs on pushig the create button:
You have a nil object when you didn't expect it!
The error occurred while evaluating nil.each_value
def create
@voucher = Voucher.new(params[:voucher])
# vvv the error occurs in this line vvv
params[:positions].each_value do |position|
@voucher.positions.build(position) unless position.values.all?(&:blank?)
end
if @voucher.save
flash[:notice] = 'Voucher was successfully created.'
redirect_to :action => 'list'
else
render :action => 'new'
end
end
This part is taken from the previous article and before I made the new changes it worked for me without any problems. It seems to me that any reference to params[:positions] is getting lost and I cant' figure out why. I have to say that my code is nearly the same as the one from this tutorial except for 'project' changed to 'voucher' and 'task' to 'position'.
I would really appreciate on any help or hint!
Thanks in advance