model Validation for Polymorphic association

0 views
Skip to first unread message

Selvaraj

unread,
May 22, 2008, 7:27:11 AM5/22/08
to bangal...@googlegroups.com
Hi All,

 I got one problem... Initially looks simple but not getting solved..

Anybody did the model validation for polymorphic association table??

class Request < ActiveRecord::Base
belongs_to :user
belongs_to :user_request,:polymorphic=>true
belongs_to :service
end

class WaterBill < ActiveRecord::Base
has_one :request,:as=>:user_request,:dependent=>:destroy

validates_presence_of(:name_of_legalperson, :message => "Should not be
blank")

end


Here validation in WaterBill model is not working..

my controller code...

def save
@requests=Request.new()
@requests.user_request=WaterBill.new(params[:water_bill])
if @requests.save
flash[:notice] = 'Water Bill Was Successfully Created.'
redirect_to :action => 'newwaterbill'
else
render :action => 'newwaterbill'
end
end


Any thing wrong in this code .. please clarify my doubts...
 
Regards
Selva


Reply all
Reply to author
Forward
0 new messages