Forum: Ruby on Rails Rss feed items disappear using feedtools?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
2cf7af8ebb619eeb30178dd8855245b8?d=identicon&s=25 charlie (Guest)
on 2006-04-30 08:54
I have met a problem on Feedtools and felt very confused about it:
The feed that I generated using feedtools can not be read correctedly by
feedtools,while rss from other websites can be read.
Still,the code for rss generating:
 def userrss
    @user = User.find_by_id(params[:id])
    @articles = @user.articles(:all,:order => 'updated_at desc',:limit
=> 15)
    @headers["Content-Type"] = "application/xml; charset=utf-8"
    @feed = FeedTools::Feed.new
    @feed.title = "#{@user.login}"
    @feed.author = "#{@user.login }"
    @feed.link = "http://localhost:3000"
    @feed.description = "rss for #{@user.login}"
    @articles.each do|@article|
      @feed_item = FeedTools::FeedItem.new
      @feed_item.title = "title"
      @feed_item.link = " http://localhost:3000/"
      @feed_item.description = render_to_string(:layout => false,
:template => "feeds/view.rhtml")
      @feed.entries << @feed_item
    end
 end
and @feed.build_xml('rss', 2.0) in the userrss.rxml file

the generated rss can be read by any desktop rss reader correctedly

Following is the code for rss read:
controller:
@feed = FeedTools::Feed.open("http://127.0.0.1:3000/feeds/userrss/1")
view:
<div class="contentBox">
 <h4><a href="<%= h @feed.link %>">
     <%= @feed.title %></a></h4>
 <p><%= @feed.description %></p>

<% for feed_item in @feed.items %>
  <div class="feedItemBox">
     <h5><a href="<%= h feed_item.link %>">
          <%= feed_item.title %></a>
     </h5>
      <p><%= feed_item.description %></p>
  </div>
<% end %>
</div>

The results show that @feed.items will be empty in the above
view,therefore only @feed.title,@feed.description and @feed.link can be
displayed,with the following items are left blank.

If I use <%= @feed.feed_data %> in the view,I can see the whole data
displayed normally with all the items of the channel_node,but the
@feed.items or @feed.entries will return empty, why? Can anybody here
help me with this problem?
2cf7af8ebb619eeb30178dd8855245b8?d=identicon&s=25 charlie (Guest)
on 2006-04-30 10:14
...
It is because of the extra code:
    @headers["Content-Type"] = "application/xml; charset=utf-8"
if I deleted it,then everything will be ok
..
E28c35323f624b8b9ed8712e25105454?d=identicon&s=25 Ray Baxter (Guest)
on 2006-05-03 19:11
(Received via mailing list)
charlie wrote:

> The results show that @feed.items will be empty in the above
> view,therefore only @feed.title,@feed.description and @feed.link can be
> displayed,with the following items are left blank.

So you can create a valid feed using this writing code and you can read
valid feeds using this reading code, but you can't simultaneously read
and write valid code. I mentioned yesterday that reading and writing
simultaneously might not work.

You really should try debugging these problems by writing the feed out
to a file and then reading that file. That rules out many possible
sources of error that you won't see in a production.

If that works, then why don't you try starting two instances of webrick.
This could be a problem in allow_concurrency, or it could be that you
are overwriting your own values.

--

Ray
This topic is locked and can not be replied to.