Displaying 20 results from an estimated 3000 matches similar to: "creating a computed column with activerecord for to_xml"
2006 Jul 31
2
is it possible to make to_xml use underscore instead of dash?
Hi all,
I am getting ActiveRecord to produce XML with
render :xml => @user.to_xml
However, on the client end it is a bit annoying for me to deal with
attributes like first-name. I would much rather have first_name.
Is there any way for me to turn off the behavior of converting _ to -?
This seems to be done by a call to dasherize inside the to_xml of
2008 Jan 08
1
howto rebuild a object from a received xml hash structure ?
im my web server app , i have an action to be used as a REST web
service
# GET /user/membership.xml?email=emailaddress
def membership
@user = User.find_by_email(params[:email])
respond_to do |format|
format.xml { render :xml => @user.to_xml( :only =>
[ :first_name, :last_name, :display_name, :membership_type, :membership_at], :skip_types
=> true)}
end
end
my
2006 Jan 25
1
xx-0.1.0 : xhtml and xml make it twice as dirty
NAME
xx - twice as dirty
SYNOPSIS
~ > gem install "double x"
require "xx"
include XX::XHTML
doc = xhtml_{
html_{
head_{ title_{ " go xx! " } }
body_{ " one more and it would be illegal " }
}
}
URI
http://rubyforge.org/frs/?group_id=1024
DESCRIPTION
xx is a library designed to extend ruby objects
2007 Feb 21
1
Rendering all the elements when calling Array#to_xml
When I call to_xml on an array, I want it to get the XML for all the
elements in it. I''ve defined to_xml in my class.
>> r.to_xml
=> "<video><id>1</id><views>2</views></video>"
>> a = [r]
=> [#<StatisticsReport:0x3259f38 @video_id=1, @views=2>]
>> a.to_xml
=> "<?xml version=\"1.0\"
2009 Jan 09
2
Confused about to_xml() in ActiveRecord::Base subclass
Since all my efforts to control how to_xml() is formatting dates has
failed, I''m now considering writing my own to_xml(). However, from
the limited examples I''ve found, I just don''t understand how to
actually reference the columns for the records in my record set.
Here''s a simplified view of my ActiveRecord object:
class Errors < ActiveRecord::Base
2006 Aug 15
2
to_xml and underscores
hi,
i am looking for a solution whereupon
calling myEntityObject.to_xml does not
convert my attributes containing underscores
into hyphens.
at the moment an attribute named "my_own_attribute"
is converted into <my-own-attribute>.
does anybody have an idea how to change that
and have to_xml generate <my_own_attribute>
thanks
ciao robertj
--
Posted via
2007 Feb 15
3
Restrict attributes in to_xml
For example, let''s say I have a User model with 2 attributes:
1. pw_hash
2. pw_salt
I don''t want these to show up in the to_xml method. How do I keep to_xml
from using these attributes?
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby on Rails:
2010 Feb 11
2
Inconsistent Hash#to_xml Method
I have a unit test that demonstrates some inconsistent behavior with a
Hash being converted to XML with the :root option. Sometimes it works
fine:
Hash.new.to_xml(:root => ''test'')
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<test>\n</test>\n"
But sometimes I get an argument error:
Hash.new.to_xml(:root =>
2009 Jan 05
5
ROXML versus simple to_xml
How they differ?
Does the to_xml method of the classes array/hash/object is based on
ROXML lib?
As I see in http://roxml.rubyforge.org/#quickstart, roxml needs we
define the class (class Book in the guide) before to convert a object
to xml. Moreover, the method to_xml (when not using "include ROXML")
just accepts any existing object, what is much suitable.
I need to compare and tranfer
2010 Mar 08
1
to_xml repeating elements and plain strings
Say I want to output XML like this:
<myXML>
<id>123</id>
<fruit>apple</fruit>
<fruit>banana</fruit>
<fruit>pear</fruit>
<fruit>lemon</fruit>
</myXML>
Is there a way of doing that with to_xml?
It seems like there''s two problems: to_xml always creates a wrapping
element <fruits> when it encounters an
2006 Jun 19
6
to_xml depth ...
hello,
The "render :xml => myFriends.to_xml", return something like:
<people>
<person>
<id type="integer">2</id>
...
<person>
But a Person has a "has_many" relationship and they are not in the xml,
=> so is it possible to change the depth of the marshall process ?
if it not possible, what are the "rails
2008 May 23
3
Problem with .to_xml and Hash.form_xml ?
Hi,
i m trying to do some kind of database dump using .to_xml
and after i try to fill my database back (well an other) with the
content of the xml.
Right now i m doing that :
@xml = Video.find(:all).to_xml(:include=>[:vlogiciels])
it does produce :
<videos>
<video>
<mycolumns>
.....
<vlogiciels>
<logiciel>
2009 Jan 21
1
AR to_xml problem with associations, Builder::XmlMarkup#to_a
When I do a to_xml(with a block) on an association of a model I got a
Builder::XmlMarkup#to_ary should return Array
Example that does not work.
@intervenant = Intervenant.find(params[:id])
output = @intervenant.to_xml( :skip_types => false, :dasherize =>
false) do |xml|
@intervenant.individu.to_xml( :builder => xml, :skip_instruct =>
true, :skip_types => false,
2007 Jan 17
4
changing the default behaviour of to_xml for has-many: associations
I recently submitted a patch to work around an issue I was having &
added a new optional behaviour to the to_xml method but on further
reflection I wonder if the default behaviour should be changed.
The gory detail, documentation and test case is all here...
http://dev.rubyonrails.org/ticket/7004
Here''s a brief example...
class Person < ActiveRecord::Base
has_many: children
2007 Dec 12
2
to_xml ignore fields
Hi!
I''d like to know how to (most easily) ignore some elements from produced
XML ..
for example: @people.to_xml produces:
<person>
<id>2</id>
<name>bob</name>
<street>carson street</street>
</person>
...
How can I *not* produce the "ID" field for example?
Thank you!
--
Posted via http://www.ruby-forum.com/.
2006 Jul 22
3
refactoring commonly used aggregations
I have a number of models that use an aggregation to combine First Name,
Middle Initial and Last Name and they have been working fine. I am
looking to clean this up, DRY it if possible.
I have things like this in application.rb
class Clwholename
attr_reader :first_name, :middle_initial, :last_name
def initialize(first_name, middle_initial, last_name)
@first_name = first_name
2010 Feb 20
1
Advanced use of to_xml and to_json
Hello,
I''m working on a Rails app which has a REST API. I manage two formats
JSON and XML.
Very often to simplify the use if the API, I''m making includes. But when
you add params to to_json and to_xml like :only, :except, it''s not only
applied on the root object but on all the objects included.
Do you know libs or methods to answer to these different problems:
* Tell
2008 May 24
1
to_xml for Foo::Bar active records
20 / 20 hind sight, I would probably do things different today but I
have most of my active record classes under different parent classes.
For example:
module Foo
class Bar < ActiveRecord::Base
...
end
end
The to_xml for this produces <foo/bar> .... </foo/bar>
The / in a tag name is not allowed. Questions:
1) Is this a bug?
2) If so, suggestion of what to convert it to?
2006 Jun 09
2
Timzones, UTC, and to_xml()
Does anyone know a good way to hook into the AR to_xml() method to
allow for adjusting datetimes to a user''s timezone?
Basically I want a user to be able dump all their data before
cancelling an account. I store all datetime info as UTC as per the
recommendations of Jamis Buck and Scott Barron in the Rails Recipe
article "Dealing with Timezones". Come to think of it I bet
2007 May 17
4
Namespaced model valid #to_xml support in ActiveRecord, ActiveSupport and ActiveResource
Hi,
Attached are links to two patches I submitted via the RoR Trac system
a week or so ago:
http://dev.rubyonrails.org/ticket/8305
http://dev.rubyonrails.org/ticket/8308
I refrained from creating a new Trac ticket for ARes, which will be
affected if both of these patches are accepted by Core.
There are a couple of workarounds for this issue, but it would be nice
for AR, AS and ARes to output