Nave
Nave

Reputation: 715

How do I check if it returns a null?

i should check whether there is some values based on this condition. if there is some, then i should do one action or else do a different action. i work on rails, mysql and xp
this is not working @test.nil?
suggest me a alternate way
@test=Model.find(:all,:conditions=>"id=@someid")
thanks in advance

Upvotes: 0

Views: 1039

Answers (1)

John Topley
John Topley

Reputation: 115362

@test.nil? should work fine. It's probably not working because your find method is wrong. Try this instead:

@test = Model.find_by_id(@someid)

An alternative syntax is:

@test = Mode.find(@someid)

—Which will raise a RecordNotFound exception if the record doesn't exist.

Upvotes: 7

Related Questions