On 5/22/08, Selvaraj Subbaian
<rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
wrote:> 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...
If you use the debugger you can easily see what the model''s error hash
contains.
script/server --debugger
Then add ''debug'' near where the code is causing a problem.
Try changing your code so you can actually get at the errors:
@request.save
if @request.new_record?
debug
end
Also, I would choose a model name other than Request, seems too easily
confused request.post and friends.
--
Greg Donald
http://destiney.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
-~----------~----~----~----~------~----~------~--~---