Re: Help required...

Robert Walker
Thu, 30 Sep 2010 14:25:47 -0000

Newb Newb wrote:
> Actually I would like to know how to send the picture name in the xml
> response
>
> fox example picture = Picture.find(params[:id])
>
> Here i need to send the picture.id in the xml response...

I''m not sure what you''re really asking, but maybe this will
help:

Terminal
--------------
rails g scaffold picture name:string mime_type:string url:string
rake db:migrate
rails s (or ./script/server for Rails < 3.0)

THE CODE...

picture.rb
---------------
class Picture < ActiveRecord::Base
end

pictures_controller.rb
------------------
  # GET /pictures/1
  # GET /pictures/1.xml
  def show
    @picture = Picture.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @picture }
    end
  end

Terminal (again)
------------------------
$ curl http://localhost:3000/pictures/1.xml
<?xml version="1.0" encoding="UTF-8"?>

  <created-at
type="datetime">2010-09-30T14:14:32Z</created-at>
  <id type="integer">1</id>
  <mime-type>image/jpeg</mime-type>
  <name>Fox Example Picture</name>
  <updated-at
type="datetime">2010-09-30T14:14:32Z</updated-at>

<url>http://images.nationalgeographic.com/wpf/media-live/photos/000/006/cache/red-fox_679_600x450.jpg</url>

--
Posted via http://www.ruby-forum.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-/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