I done plenty of saves before in rails, but I must be missing
something simple with this. Can a fresh set of eyes take a look at
this and see why it is not saving:
def addcash(uid)
c = Trade.new
c.attributes = {"user_id" => uid,
"tradetype" => ''9'',
"cash" => 10000}
breakpoint
if c.save
breakpoint
flash[''notice''] = "Signup successful."
end
end
Sorry, I hit tab and space trying to clean up some spacing and gmail
sent the email. Here is my full email:
def addcash(uid)
c = Trade.new
c.attributes = {"user_id" => uid,
"tradetype" => ''9'',
"cash" => 10000}
breakpoint
if c.save
breakpoint
flash[''notice''] = "Signup
successful."
end
end
The first breakpoint generates this for c (the second breakpoint never
triggers):
irb(#<AccountController:0x3a01f78>):001:0> c=> #<Trade:0x39ca7f0
@new_record=true, @attributes={"status"=>"A",
"created_on"=>"0000-00-00 00:00:00",
"price"=>"0",
"updated_on"=>"0000-00-00 00:00:00",
"profit"=>"0.00",
"units"=>"0",
"product_id"=>"0",
"cash"=>10000,
"tradetype"=>"9",
"user_id"=>25}>
The table it is writing to has the following structure:
ield Type Collation Null Key Default
Extra Privileges Comment
---------- ------------- ----------------- ------ ------
------------------- -------------- -------------------------------
-------
id int(11) NULL PRI (NULL)
auto_increment
user_id int(7) NULL 0
product_id int(11) NULL 0
tradetype int(2) NULL 0
units int(7) NULL 0
price int(7) NULL 0
created_on datetime NULL
0000-00-00 00:00:00
updated_on datetime NULL
0000-00-00 00:00:00
status char(2) latin1_swedish_ci A
profit decimal(10,2) NULL 0.00
cash decimal(6,2) NULL 0.00
Thanks very much,
Steve
Try adding: unless c.valid? p c.errors end ..before the first breakpoint. Also, shouldn''t that be flash[:notice]? I didn''t know you could use a string like that. Steve Odom wrote:> I done plenty of saves before in rails, but I must be missing > something simple with this. Can a fresh set of eyes take a look at > this and see why it is not saving: > > def addcash(uid) > c = Trade.new > c.attributes = {"user_id" => uid, > "tradetype" => ''9'', > "cash" => 10000} > breakpoint > if c.save > breakpoint > flash[''notice''] = "Signup successful." > end > end
Perfect, Wilson. I never used that before. Very hand and identified my problem - validator in the model looking for a postive number for one of the variables. Steve On 7/28/05, Wilson <defiler-ifvz4xmYPRU@public.gmane.org> wrote:> Try adding: > unless c.valid? > p c.errors > end > ..before the first breakpoint.