def before_create
Storage.create!(:product_id => self.product_id, :current_quantity
=> self.quantity, :stg_data => purchase.prc_data)
end
end
as you can see I’m using “before_create” callback. It was working just
fine two weeks ago, but today I realize it wasn’t. I don’t know why.
The only change is that now I’m using jquery instead of prototype
Use ruby-debug to break in here and inspect the data to see what is
going on. See the Rails Guide on debugging if you don’t know how to
do this.
end
end
as you can see I’m using “before_create” callback. It was working just
fine two weeks ago, but today I realize it wasn’t. I don’t know why.
The only change is that now I’m using jquery instead of prototype
You have not actually said what is not working. Have you looked in
the rails log to see if there is anything of interest there?
The callback is not working. When I call to “Storage.create!” it
should create a new Storage, but now the storage is never create.
Thanks for your help, I’ll try debugging.
Debugging will tell you whether the callback is being called. If you
assign the result of Storage.create! to a variable and break after
that then you will be able to inspect that object.
Have you got any validations on Storage that could prevent it from
saving?
Please don’t top post, it makes it difficult to follow the thread.
Insert your reply at appropriate points in the previous message.
Thanks.
Debugging will tell you whether the callback is being called. If you
assign the result of Storage.create! to a variable and break after
that then you will be able to inspect that object.
class MyModel < ActiveRecord::Base
before_create :do_my_action
def do_my_action
.
end
end
tom
On Aug 16, 2011, at 22:39 , Angelo C. wrote:
I have this model
Use ruby-debug to break in here and inspect the data to see what is
You have not actually said what is not working. Have you looked in
the rails log to see if there is anything of interest there?
and when I “inspect” the variable “stg” I got “stg => nil” as result
Remember that you can inspect data and evaluate expressions in the debugger.
blk => #<Proc:0xc302b34@/usr/local/ruby/lib/ruby/gems/1.9.1/gems/
NameError Exception: undefined local variable or method `stg’ for
#DetailPurchase:0xb4d3054
I have occasionally had problems with the debugger statement at the
end of a method with it apparently dropping out of the method before
breaking, so that variables are no longer accessible. Add an extra
line after the debugger statement (i=0 for example) to give it
something to break on.
On a separate issue, looking at the message you get, are you using
ruby 1.9.1? If so then upgrade to 1.9.2 or go back to 1.8.7, ruby
1.9.1 does not work reliably with rails. This may have nothing to do
with your problem.
I note that you still have not answered my question (unless I missed
it), have you any validations on the Storage model?
On a separate issue, looking at the message you get, are you using
ruby 1.9.1? If so then upgrade to 1.9.2 or go back to 1.8.7, ruby
1.9.1 does not work reliably with rails. This may have nothing to do
with your problem.
No, I’m using ruby 1.9.2
I note that you still have not answered my question (unless I missed
it), have you any validations on the Storage model?
Finally, I found the problem. It was a validation on storage, I
removed it, and everything works perfect
On a separate issue, looking at the message you get, are you using
ruby 1.9.1? If so then upgrade to 1.9.2 or go back to 1.8.7, ruby
1.9.1 does not work reliably with rails. This may have nothing to do
with your problem.
I’m using ruby 1.9.2
I note that you still have not answered my question (unless I missed
it), have you any validations on the Storage model?
I have validations for presence (product_id, current_quantity and
stg_data)
and for numericality (current_quantity)
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.