can any one help me out how to build an xml api with out using database .
Jump to content
The ultimate community for Ruby on Rails developers.
Posted 12 February 2014 - 04:43 PM
What would you have in the API if not data from a database?
In your controller, e.g. users_controller.rb, you can have an index method. Here we'll just respond to .xml and let the view handle the xml generation.
def index @users = User.all responds_to do |format| format.html # If you want to still let the html view render format.xml end end
Inside our view folder, we'll have an users folder and in this we can create an index.xml.erb file. This could look like so:
<?xml version="1.0" encoding="UTF-8"?> <users> <% @users.each do |user| %> <user> <name><%= user.name %></name> ... </user> <% end %> </users>
0 members, 0 guests, 0 anonymous users