Hello everyone I have this model class DetailPurchase < ActiveRecord::Base belongs_to :purchase, :foreign_key => ''purchase_id'' belongs_to :product, :foreign_key => ''product_id'' belongs_to :buy_order_detail, :foreign_key => ''buy_detail_id'' 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 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 16 August 2011 17:40, Angelo Cordova <acordinz-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hello everyone > > I have this model > > class DetailPurchase < ActiveRecord::Base > belongs_to :purchase, :foreign_key => ''purchase_id'' > belongs_to :product, :foreign_key => ''product_id'' > belongs_to :buy_order_detail, :foreign_key => ''buy_detail_id'' > > def before_create > Storage.create!(:product_id => self.product_id, :current_quantity > => self.quantity, :stg_data => purchase.prc_data)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 prototypeYou have not actually said what is not working. Have you looked in the rails log to see if there is anything of interest there? Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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. On Aug 16, 3:58 pm, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 16 August 2011 17:40, Angelo Cordova <acord...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Hello everyone > > > I have this model > > > class DetailPurchase < ActiveRecord::Base > > belongs_to :purchase, :foreign_key => ''purchase_id'' > > belongs_to :product, :foreign_key => ''product_id'' > > belongs_to :buy_order_detail, :foreign_key => ''buy_detail_id'' > > > def before_create > > Storage.create!(:product_id => self.product_id, :current_quantity > > => self.quantity, :stg_data => purchase.prc_data) > > 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? > > Colin-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 16 August 2011 21:39, Angelo Cordova <acordinz-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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. Colin> > On Aug 16, 3:58 pm, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: >> On 16 August 2011 17:40, Angelo Cordova <acord...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >> > Hello everyone >> >> > I have this model >> >> > class DetailPurchase < ActiveRecord::Base >> > belongs_to :purchase, :foreign_key => ''purchase_id'' >> > belongs_to :product, :foreign_key => ''product_id'' >> > belongs_to :buy_order_detail, :foreign_key => ''buy_detail_id'' >> >> > def before_create >> > Storage.create!(:product_id => self.product_id, :current_quantity >> > => self.quantity, :stg_data => purchase.prc_data) >> >> 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? >> >> Colin > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
you missed definition of that callback class MyModel < ActiveRecord::Base before_create :do_my_action def do_my_action …. end end tom On Aug 16, 2011, at 22:39 , Angelo Cordova wrote:> 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. > > On Aug 16, 3:58 pm, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: >> On 16 August 2011 17:40, Angelo Cordova <acord...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >>> Hello everyone >> >>> I have this model >> >>> class DetailPurchase < ActiveRecord::Base >>> belongs_to :purchase, :foreign_key => ''purchase_id'' >>> belongs_to :product, :foreign_key => ''product_id'' >>> belongs_to :buy_order_detail, :foreign_key => ''buy_detail_id'' >> >>> def before_create >>> Storage.create!(:product_id => self.product_id, :current_quantity >>> => self.quantity, :stg_data => purchase.prc_data) >> >> 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? >> >> Colin > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.-- ==============================================================================Tomas Meinlschmidt, MS {MCT, MCP+I, MCSE, AER}, NetApp Filer/NetCache www.meinlschmidt.com www.maxwellrender.cz www.lightgems.cz ============================================================================== -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 16 August 2011 21:50, Tom Meinlschmidt <tomas-ooGa/4BNRfTT2+6r9I86XQ@public.gmane.org> wrote:> you missed definition of that callback > > class MyModel < ActiveRecord::Base > before_create :do_my_actionThat can''t be the problem because it used to work and the only change the OP made was to use jQuery instead of prototype :) @OP: have a look at your Source Control System logs (I presume you use git or something similar) to see what you actually changed. Colin> > def do_my_action > …. > end > end > > tom > > On Aug 16, 2011, at 22:39 , Angelo Cordova wrote: > >> 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. >> >> On Aug 16, 3:58 pm, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: >>> On 16 August 2011 17:40, Angelo Cordova <acord...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >>> >>>> Hello everyone >>> >>>> I have this model >>> >>>> class DetailPurchase < ActiveRecord::Base >>>> belongs_to :purchase, :foreign_key => ''purchase_id'' >>>> belongs_to :product, :foreign_key => ''product_id'' >>>> belongs_to :buy_order_detail, :foreign_key => ''buy_detail_id'' >>> >>>> def before_create >>>> Storage.create!(:product_id => self.product_id, :current_quantity >>>> => self.quantity, :stg_data => purchase.prc_data) >>> >>> 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? >>> >>> Colin >> >> -- >> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. >> To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. > > -- > ==============================================================================> Tomas Meinlschmidt, MS {MCT, MCP+I, MCSE, AER}, NetApp Filer/NetCache > > www.meinlschmidt.com www.maxwellrender.cz www.lightgems.cz > ==============================================================================> > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
> 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. >I tried this def before_create debugger stg = Storage.create!(:product_id => self.product_id, :current_quantity => self.quantity, :stg_data => purchase.prc_data) end and when I "inspect" the variable "stg" I got "stg => nil" as result> > > > > > > > > > On Aug 16, 3:58 pm, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > >> On 16 August 2011 17:40, Angelo Cordova <acord...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > >> > Hello everyone > > >> > I have this model > > >> > class DetailPurchase < ActiveRecord::Base > >> > belongs_to :purchase, :foreign_key => ''purchase_id'' > >> > belongs_to :product, :foreign_key => ''product_id'' > >> > belongs_to :buy_order_detail, :foreign_key => ''buy_detail_id'' > > >> > def before_create > >> > Storage.create!(:product_id => self.product_id, :current_quantity > >> > => self.quantity, :stg_data => purchase.prc_data) > > >> 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? > > >> Colin > > > -- > > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 17 August 2011 15:31, Angelo Cordova <acordinz-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> >> 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. >> > I tried this > > def before_create > debugger > stg = Storage.create!(:product_id => > self.product_id, :current_quantity > => self.quantity, :stg_data => purchase.prc_data) > end > > and when I "inspect" the variable "stg" I got "stg => nil" as resultThat is not surprising since you have broken *before* the line that allocates stg. Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
> > I tried this > > > def before_create > > debugger > > stg = Storage.create!(:product_id => > > self.product_id, :current_quantity > > => self.quantity, :stg_data => purchase.prc_data) > > end > > > and when I "inspect" the variable "stg" I got "stg => nil" as result > > That is not surprising since you have broken *before* the line that > allocates stg. > > ColinIf I break after that line... "stg" does not appear -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 18 August 2011 14:50, Angelo Cordova <acordinz-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:>> > I tried this >> >> > def before_create >> > debugger >> > stg = Storage.create!(:product_id => >> > self.product_id, :current_quantity >> > => self.quantity, :stg_data => purchase.prc_data) >> > end >> >> > and when I "inspect" the variable "stg" I got "stg => nil" as result >> >> That is not surprising since you have broken *before* the line that >> allocates stg. >> >> Colin > > If I break after that line... "stg" does not appearwhat do you mean it does not appear? Remember that you can inspect data and evaluate expressions in the debugger. Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
> >> > I tried this > > >> > def before_create > >> > debugger > >> > stg = Storage.create!(:product_id => > >> > self.product_id, :current_quantity > >> > => self.quantity, :stg_data => purchase.prc_data) > >> > end > > >> > and when I "inspect" the variable "stg" I got "stg => nil" as result > > >> That is not surprising since you have broken *before* the line that > >> allocates stg. > > >> Colin > > > If I break after that line... "stg" does not appear > > what do you mean it does not appear? > > Remember that you can inspect data and evaluate expressions in the debugger. > > ColinWhen I used debugger the first time (in the line before the callback) I chose option "var local" and I got stg => nil But when I use debugger after that line I get this blk => #<Proc:0xc302b34@/usr/local/ruby/lib/ruby/gems/1.9.1/gems/ activerecord-3.0.9/lib/active_record/callbacks.rb:277> halted => false key => nil name => nil result => true value => 88 And if I try to "inspect" stg I get var instance stg NameError Exception: undefined local variable or method `stg'' for #<DetailPurchase:0xb4d3054> -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 18 August 2011 17:48, Angelo Cordova <acordinz-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> >> >> > I tried this >> >> >> > def before_create >> >> > debugger >> >> > stg = Storage.create!(:product_id => >> >> > self.product_id, :current_quantity >> >> > => self.quantity, :stg_data => purchase.prc_data) >> >> > end >> >> >> > and when I "inspect" the variable "stg" I got "stg => nil" as result >> >> >> That is not surprising since you have broken *before* the line that >> >> allocates stg. >> >> >> Colin >> >> > If I break after that line... "stg" does not appear >> >> what do you mean it does not appear? >> >> Remember that you can inspect data and evaluate expressions in the debugger. >> >> Colin > > When I used debugger the first time (in the line before the callback) > I chose option "var local" and I got > > stg => nil > > But when I use debugger after that line I get this > > blk => #<Proc:0xc302b34@/usr/local/ruby/lib/ruby/gems/1.9.1/gems/ > activerecord-3.0.9/lib/active_record/callbacks.rb:277> > halted => false > key => nil > name => nil > result => true > value => 88 > > And if I try to "inspect" stg I get > > var instance stg > 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? Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
> 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) -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
> 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 Thanks for your help, thanks for your patience -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.