David Kahn
2011-Apr-27 18:25 UTC
Can not create model instance via params on specific model but can on others....
Anyone have an idea on this? Got a weird situation where on a specific model I can not create an instance using params, yet it works fine on other models. The model which does not work is a stock model, there is no logic in it. Ruby 1.8.7/Rails 3.0.5. Does not work: (rdb:1) PaymentTransaction.create(:purchase_id => 3) #<PaymentTransaction id: 2, purchase_id: nil, action: nil, amount: nil, success: nil, authorization: nil, message: nil, params: nil, created_at: "2011-04-27 18:18:59", updated_at: "2011-04-27 18:18:59"> But this works (but is ugly): (rdb:1) bpt = PaymentTransaction.new #<PaymentTransaction id: nil, purchase_id: nil, action: nil, amount: nil, success: nil, authorization: nil, message: nil, params: nil, created_at: nil, updated_at: nil> (rdb:1) bpt.purchase_id = 3 3 (rdb:1) bpt.save true (rdb:1) PaymentTransaction.find_by_bet_id(3) #<PaymentTransaction id: 3, purchase_id: 3, action: nil, amount: nil, success: nil, authorization: nil, message: nil, params: nil, created_at: "2011-04-27 18:22:46", updated_at: "2011-04-27 18:22:46"> And this works: (rdb:1) Team Team(id: integer, sport_id: integer, name: string, created_at: datetime, updated_at: datetime) (rdb:1) Team.create(:sport_id => 5, :name => ''xxxx'') #<Team id: 1, sport_id: 5, name: "xxxx", created_at: "2011-04-27 18:18:31", updated_at: "2011-04-27 18:18:31"> -- 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.
Kendall Gifford
2011-Apr-27 18:34 UTC
Re: Can not create model instance via params on specific model but can on others....
On Wednesday, April 27, 2011 12:25:28 PM UTC-6, DK wrote:> > Anyone have an idea on this? Got a weird situation where on a specific > model I can not create an instance using params, yet it works fine on other > models. The model which does not work is a stock model, there is no logic in > it. Ruby 1.8.7/Rails 3.0.5. > > Does not work: > > (rdb:1) PaymentTransaction.create(:purchase_id => 3) > #<PaymentTransaction id: 2, purchase_id: nil, action: nil, amount: nil, > success: nil, authorization: nil, message: nil, params: nil, created_at: > "2011-04-27 18:18:59", updated_at: "2011-04-27 18:18:59"> > > But this works (but is ugly): > > (rdb:1) bpt = PaymentTransaction.new > #<PaymentTransaction id: nil, purchase_id: nil, action: nil, amount: nil, > success: nil, authorization: nil, message: nil, params: nil, created_at: > nil, updated_at: nil> > (rdb:1) bpt.purchase_id = 3 > 3 > (rdb:1) bpt.save > true > (rdb:1) PaymentTransaction.find_by_bet_id(3) > #<PaymentTransaction id: 3, purchase_id: 3, action: nil, amount: nil, > success: nil, authorization: nil, message: nil, params: nil, created_at: > "2011-04-27 18:22:46", updated_at: "2011-04-27 18:22:46"> > > > And this works: > > (rdb:1) Team > Team(id: integer, sport_id: integer, name: string, created_at: datetime, > updated_at: datetime) > (rdb:1) Team.create(:sport_id => 5, :name => ''xxxx'') > #<Team id: 1, sport_id: 5, name: "xxxx", created_at: "2011-04-27 18:18:31", > updated_at: "2011-04-27 18:18:31"> > >You don''t have something like: attr_protected :puchase_id in your PaymentTransaction model do you? [http://api.rubyonrails.org/classes/ActiveModel/MassAssignmentSecurity/ClassMethods.html#method-i-attr_protected] -- 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.
David Kahn
2011-Apr-27 18:36 UTC
Re: Re: Can not create model instance via params on specific model but can on others....
On Wed, Apr 27, 2011 at 1:34 PM, Kendall Gifford <zettabyte-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote:> > > On Wednesday, April 27, 2011 12:25:28 PM UTC-6, DK wrote: >> >> Anyone have an idea on this? Got a weird situation where on a specific >> model I can not create an instance using params, yet it works fine on other >> models. The model which does not work is a stock model, there is no logic in >> it. Ruby 1.8.7/Rails 3.0.5. >> >> Does not work: >> >> (rdb:1) PaymentTransaction.create(:purchase_id => 3) >> #<PaymentTransaction id: 2, purchase_id: nil, action: nil, amount: nil, >> success: nil, authorization: nil, message: nil, params: nil, created_at: >> "2011-04-27 18:18:59", updated_at: "2011-04-27 18:18:59"> >> >> But this works (but is ugly): >> >> (rdb:1) bpt = PaymentTransaction.new >> #<PaymentTransaction id: nil, purchase_id: nil, action: nil, amount: nil, >> success: nil, authorization: nil, message: nil, params: nil, created_at: >> nil, updated_at: nil> >> (rdb:1) bpt.purchase_id = 3 >> 3 >> (rdb:1) bpt.save >> true >> (rdb:1) PaymentTransaction.find_by_bet_id(3) >> #<PaymentTransaction id: 3, purchase_id: 3, action: nil, amount: nil, >> success: nil, authorization: nil, message: nil, params: nil, created_at: >> "2011-04-27 18:22:46", updated_at: "2011-04-27 18:22:46"> >> >> >> And this works: >> >> (rdb:1) Team >> Team(id: integer, sport_id: integer, name: string, created_at: datetime, >> updated_at: datetime) >> (rdb:1) Team.create(:sport_id => 5, :name => ''xxxx'') >> #<Team id: 1, sport_id: 5, name: "xxxx", created_at: "2011-04-27 >> 18:18:31", updated_at: "2011-04-27 18:18:31"> >> >> > You don''t have something like: > > attr_protected :puchase_id > > in your PaymentTransaction model do you? >Ahhhh, duh, I have ActiveRecord::Base.send(:attr_accessible, nil) in application.rb..... Right on, thanks!> > [ > http://api.rubyonrails.org/classes/ActiveModel/MassAssignmentSecurity/ClassMethods.html#method-i-attr_protected > ] > > > -- > 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. >-- 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.