I''m getting the following error: undefined method `base_amount'' for []:Array It''s talking about line 6 1: def pay_commission 2: @product = Product.find(params[:id]) 3: pay = PayRate.find(:all, 4: :select => "base_amount, special_amount", 5: :conditions => ["deleted_yn=0 and pay_type_id = ?", @product.pay_type_id]) 6: @product.amount = pay.base_amount 7: @product.special = pay.special_amount 8: @product.status = ''Paid'' 9: end If i take out lines 6 and 7, everything works fine. Also, when i look at the terminal session, the correct SQL is created and I can run that in MySQL to get the correct fields and values. Anyone have any ideas? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Is deleted_yn is actually a boolean field if a pay rate has been deleted or not. You could call this deleted. Then you could do: has_many :pay_rates, :conditions => "deleted = 0" in your Product model. The reason why it''s giving you that error is because you''re retreving MANY payrates instead of just the one. Perhaps with this new code you can do @ product.pay_rates.first.amount On Jan 21, 2008 4:21 PM, George Pasley <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > I''m getting the following error: > > undefined method `base_amount'' for []:Array > > It''s talking about line 6 > > 1: def pay_commission > 2: @product = Product.find(params[:id]) > 3: pay = PayRate.find(:all, > 4: :select => "base_amount, special_amount", > 5: :conditions => ["deleted_yn=0 and pay_type_id = ?", > @product.pay_type_id]) > 6: @product.amount = pay.base_amount > 7: @product.special = pay.special_amount > 8: @product.status = ''Paid'' > 9: end > > If i take out lines 6 and 7, everything works fine. Also, when i look > at the terminal session, the correct SQL is created and I can run that > in MySQL to get the correct fields and values. Anyone have any ideas? > -- > Posted via http://www.ruby-forum.com/. > > > >-- Ryan Bigg http://www.frozenplague.net Feel free to add me to MSN and/or GTalk as this email. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi, pay = PayRate.find(:all, :select => "base_amount, special_amount", :conditions => ["deleted_yn=0 and pay_type_id = ?", @product.pay_type_id]) You got the array of records from PayRate table because you find all records based on that conditions.. So you have to use loop you can try this pay.each {|p| puts p.base_amount} If you use find :first your code is correct @product.amount = pay.base_amount @product.special = pay.special_amount Regards Abirami -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks a lot. That fixed it Abirami Selvam wrote:> Hi, > pay = PayRate.find(:all, > :select => "base_amount, special_amount", > :conditions => ["deleted_yn=0 and pay_type_id = ?", > @product.pay_type_id]) > > You got the array of records from PayRate table because you find all > records based on that conditions.. So you have to use loop > > you can try this > > pay.each {|p| puts p.base_amount} > > If you use find :first your code is correct > > @product.amount = pay.base_amount > @product.special = pay.special_amount > > Regards > Abirami-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---