So I am doing a lynda.com Rails essential training tutorial, and I am getting an error that the video tutorial does not. I assume this has to do with the different versions of Ruby & Rails that I am using (the latest as of today) as opposed to the ones they used when this was recorded (I think in 2007).
This is what my controller looks like:
class PublicController < ApplicationController
def album_list
@albums = Album.find_by_sql('SELECT * FROM albums;')
end
def alt_album_list
release_date = '2011-10-01'
artist = 'Paul'
@albums = Album.find(:all,
:conditions => ["release_date <= ? AND artist LIKE ?", release_date, '%' + artist + '%'],
:order => 'release_date ASC',
:limit => 1, :offset => 1)
render(:action => 'album_list')
end
def one_album_list
release_date = '2011-10-01'
artist = 'Paul'
@album = Album.find(:first,
:conditions => ["release_date <= ? AND artist LIKE ?", release_date, '%' + artist + '%'],
:order => 'release_date ASC')
end
end
This is what my view looks like:
<html>
<head>
<title></title>
</head>
<body>
Title: <%= @album.title %><br />
Artist: <%= @album.artist %><br />
Genre: <%= @album.genre %><br />
</body>
</html>
The error I get when I load it is:
NoMethodError in Public#show_album
Showing C:/Users/<username>/music_library/app/views/public/show_album.rhtml where line #8 raised:
undefined method `title' for nil:NilClass
Extracted source (around line #8):
5:
6: <body>
7:
8: Title: <%= @album.title %><br />
9: Artist: <%= @album.artist %><br />
10: Genre: <%= @album.genre %><br />
11:
Rails.root: C:/Users/<username>/music_library
Application Trace | Framework Trace | Full Trace
app/views/public/show_album.rhtml:8:in `_app_views_public_show_album_rhtml___574395264_32579964__949661750'