I am having trouble with the title attribute on an RSS feed generated with Rails:
xml.instruct!(
:xml, :version=>"1.0", :encoding => "utf-8"
)
xml.rss(
"version" => "2.0",
"xmlns:dc" => "http://purl.org/dc/elements/1.1/"
) do
xml.channel do
xml.title("Channel Title")
xml.link("http://the.channel.com/")
xml.description("Channel Description")
xml.pubDate(Time.now.strftime("%a, %d %b %Y %H:%M:%S %z"))
xml.item do
xml.title("Item Title")
xml.link("http://the.item.com/")
xml.description("Item Description")
xml.pubDate(Time.now.strftime("%a, %d %b %Y %H:%M:%S %z"))
end
end
end
The xml.title does not result in a title tag being written to the reponse for either call!
People succeed in answering Rich Collins's questions 37% of the time (32 successes in 86 attempts).
Answers by: gsch | Fear of Fish
Try this out:
xml.instruct!
xml.rss "version" => "2.0", "xmlns:dc" => "http://purl.org/dc/elements/1.1/" do
xml.channel do
xml.title 'Channel Title'
xml.link 'http://the.channel.com/'
xml.pubDate CGI.rfc1123_date(Time.now)
xml.description 'Channel Description'
@posts.each do |post|
xml.item do
xml.title post.title
xml.link url_for( :only_path => false,
:controller => 'blog',
:action => 'article',
:id => post.id)
xml.description post.short_body.to_s
xml.pubDate CGI.rfc1123_date(post.created_at)
xml.guid url_for( :only_path => false,
:controller => 'blog',
:action => 'article',
:id => post)
end
end
end
end
I hope formatting comes out okay...bits need to be changed for you, but this is the format I use.
Why would this fix the title issue?
I did fix it btw, but it is a hack:
xml << "
I will still pay the reward if I you can tell me why xml.title isn't working.
Did you try it out? If not what rails version you on?
This did not work (I removed the posts so I didn't have to set them up). Channel Title is not written to the response
xml.instruct!
xml.rss "version" => "2.0", "xmlns:dc" => "http://purl.org/dc/elements/1.1/" do
xml.channel do
xml.title 'Channel Title'
xml.link 'http://the.channel.com/'
xml.pubDate CGI.rfc1123_date(Time.now)
xml.description 'Channel Description'
end
end