Solved

You have a nil object when you didn't expect it!

Posted on 2009-05-18
2
515 Views
Last Modified: 2013-11-13
Have a look at the code below and see if you can point me in the right direction...I'm certain it is something fundamental.
in my controller file:
 

require "RubyGems"

require "feed_tools"

		

def user_data

      @feed = FeedTools::Feed.open(params[:feed_url])

      # You can first test it with a static feed url like this

      @feed = FeedTools::Feed.open('http://www.sphred.com/combined_feed')

end
 
 

Error in browser:
 

You have a nil object when you didn't expect it!

The error occurred while evaluating nil.link
 

Extracted source (around line #105):
 

102: 	  

103: 	  <div>

104:     <h3>

105:       <a href="<%= h @feed.link %>">

106:       <%= @feed.title %></a>

107:     </h3>

108:     <p><%= @feed.description %></p>

Open in new window

0
Comment
Question by:envythe
2 Comments
 
LVL 12

Accepted Solution

by:
cminear earned 125 total points
Comment Utility
The long and short of it is that @feed is either not being set, or being set to nil, and thus trying to apply the 'link' method to a nil doesn't work.  However, I'm actually surprised you are seeing the error that you are.  Based on my quick tests, I would expect you to be seeing Exceptions being thrown by either of the "FeedTools::Feed.open" calls you gave.  

Just using IRB, I try:
  feed = FeedTools::Feed.open(nil)
I get this exception.
  NoMethodError: undefined method `scheme' for nil:NilClass
So if you called the 'user_data' action with no 'feed_url' parameter passed in, that should have thrown an exception.

If you did pass in a 'feed_url' parameter, then going to the next line, I tried:
  feed = FeedTools::Feed.open('http://www.sphred.com/combined_feed')
I get this exception:
  FeedTools::FeedAccessError: Socket error prevented feed retrieval
'www.sphred.com' does not exist (at least not from where I'm doing web and DNS requests).

So the only explanation that would account for what you are seeing is that your environment has some sort of global 'rescue' applied to the controller methods, but at the same time, the 'rescue' doesn't apply to the rendering of the page.  Are you not sharing some part of your code with us?
0
 

Author Closing Comment

by:envythe
Comment Utility
Appreciate the help - was able to work through it with your comments
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
customize rails URL 6 484
Routing in Rails 3 3 678
What is 'f.hidden_field' for? 1 295
Method Inheritance / Overriding in Ruby 5 168
Article by: narshlob
If you've ever programmed in Ruby and have come across either a proc or a lambda, you might have been wondering what the difference is between the two and when you would use one over the other. This article will try to explain the difference between…
Recently I spent hours debugging an issue in a Rails project where ActiveRecord was causing MySQL errors trying to create a User object of a class at the top level of a Single Table Inheritance model structure.  It turns out `.create` behaves differ…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now