User Tag List
Results 1 to 6 of 6
Thread: How to troubleshoot RoR
How to troubleshoot RoR
So I got:
NoMethodError in GazetteController#show_article
You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occured while evaluating nil.+
<sigh>
The controller action:
Code:
def show_article #test @gazette = Gazette.bydate('2006', '06', '04') render(:layout => 'interior', :template => 'index') end?
Your first line of defense should be well written unit tests. If you are still having problems the next step is the breakpointer - its not something I have to use often but it can be useful. Simply put the word "breakpoint" anywhere in your code, load your page and then on the command line run script/breakpointer - you'll now be able to inspect whats going on at the point where the breakpoint was encountered.
More details here:
- Join Date
- Nov 2001
- Location
- Bath, UK
- 2,498
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
What Luke said, but also, this looks suspect:
Code:
def self.bydate(year, month, day) d = @year + '-' + @month + '-' + @day
That's the sort of thing that would show up straight away in a unit test.
Also, why are you not using the date support built into Rails?
DouglasHello World
What date support? You call that date support? ;-)
RoR seems to spend half its time making my life easier (or promising to) and the other half making it harder... although I suspect that's mostly just learning curve at this point.
I did notice, sometime after coding the date formatting I need into SQL statements, that it looks like I can access the constants defined in Date via Date::CONSTANTNAME. So at some point I'll go revisit the code, but for now it's getting the job done and I'm on to other parts of the site.
- Join Date
- Mar 2004
- Location
- Toronto, Canada
- 326
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
With your app running, run "ruby script/console" in a terminal window. Also, don't forget about dev log files (very helpful for debugging): app/logs/ ...or something like that.
- Join Date
- Jul 2004
- Location
- Gerodieville Central, UK
- 446
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Just another note that many people often forget, is to use Breakpoint.breakpoint in your scripts, I find it can be a better than script/consolse as script/console only seems to be useful for interactive testing models normally.
Both when using script/console and the breakpointer, look at Dispatcher.application_reset, it will allow you to see changes in you models after updating the source - Rails Web Development - Rails powered Property Listings
Bookmarks