Help required

Dear all

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…

Please tell me that how can i go with it…

Newb N. 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"?> 2010-09-30T14:14:32Z 1 image/jpeg Fox Example Picture 2010-09-30T14:14:32Z http://images.nationalgeographic.com/wpf/media-live/photos/000/006/cache/red-fox_679_600x450.jpg

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs