Reputation: 87
I'm trying to display an image using the Feedjira gem for an RSS reader that I'm working on.
I created the method in the model:
Feed.rb
def self.feed_image(url)
Feedjira::Feed.add_common_feed_element 'img'
image = Feedjira::Feed.fetch_and_parse url
end
I'm trying to display it in the show page so I call it in the controller:
feeds_controller.rb
def show
@feed = Feed.find(params[:id])
@title = @feed.feed_title
@entries = @feed.entries
@feed_image = Feed.feed_image(params[:id]) <-----
end
I added the params in order to pull the url that is calling the feed on the show page. I try to display it in the view as follows:
show.html.erb
<h3><%= @feed.url %></h3>
<%= image_tag @feed_image %> <---------
<% @entries.each do |t| %>
<%= link_to t.title, t.url %></br>
<small><%= t.published %></small>
<%= sanitize t.summary %>
<% end %>
I'm getting the following error when I try to call it:
NoMethodError (undefined method `request_uri' for #<URI::Generic /1>):
app/models/feed.rb:19:in `feed_image'
app/controllers/feeds_controller.rb:12:in `show'
I'm not sure if it's not reading the URL correctly or where exactly I went wrong. Anyone have any idea where I went wrong.
Upvotes: 0
Views: 263