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
-- 
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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
On Aug 30, 7:36 pm, Linda K <windyli...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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 >The errors stuff is no longer in ActiveRecord::Errors, so you''re extending the wrong class. The error message you''re getting suggests that you should be extending ActiveModel::Errors instead. Fred> 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-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Cheer Fred! On Aug 30, 8:24 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Aug 30, 7:36 pm, Linda K <windyli...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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 > > The errors stuff is no longer in ActiveRecord::Errors, so you''re > extending the wrong class. The error message you''re getting suggests > that you should be extending ActiveModel::Errors instead. > > Fred > > > > > > > > > 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-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.