I'm trying to extend Active Record to write a method that will convert validation errors to xml that can be consumed by Flex. But I'm following a tutorial that has been written for Rails 2 and I'm using Rails 3.
Each time i try to call the new method i get the error
undefined method `to_xml_full' for #<ActiveModel::Errors
Here's the code from my application controller ::
`module ActiveRecord #:nodoc: class Errors #:nodoc: def to_xml_full(options={}) options[:root] ||= "errors" options[:indent] ||= 2 options[:builder] ||= Builder::XmlMarkup.new(:indent => options[:indent]) options[:builder].instruct! unless options.delete(:skip_instruct) options[:builder].errors do |e| # The @errors instance variable is a Hash inside the # Errors class @errors.each_key do |attr| @errors[attr].each do |msg| next if msg.nil? if attr == "base" options[:builder].error("message"=>msg) else fullmsg = @base.class.human_attribute_name(attr) + " " + msg options[:builder].error( "field"=>attr, "message"=>fullmsg) end end end end end end end
and here's the code from user controller that is calling the new to_xml_full method
def create @user = User.new(params[:user]) @user.points = 50 logger.info "user errors full: #{@user.errors.to_xml_full}" respond_to do |format| if @user.save sign_in(@user) format.html {redirect_to user_path(@user), :flash => { :success => "Welcome to Crowdshare App"}} #format.xml {render xml: @user, status: :created, location: @user } format.xml {render :text => "error" } else @title ="Sign up" format.html {render action: 'new'} #format.xml {render xml: @user.errors, status: :unprocessable_entity} format.xml {render :text => "error" } end end end
Any ideas where i might be going wrong? Thanks in advance