Hi All,
I've encountered the following error while trying to create a blogging application. Any ideas why?
NoMethodError in Articles#show
Showing app/views/articles/show.html.erb where line #1 raised:
undefined method `title' for []:Array
Extracted source (around line #1):
1: <h2><%= @article.title %></h2>
2:
3: <% if @article.category %>
4: <p class="category">
From my limited understanding it's trying to tell me that there is no 'title' field in my 'article' database table, however as you can see from the desc below there is cleary a 'title' field!
mysql> desc articles;
+--------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| user_id | int(11) | YES | | NULL | |
| title | varchar(255) | YES | | NULL | |
| synopsis | text | YES | | NULL | |
| body | text | YES | | NULL | |
| published | tinyint(1) | YES | | 0 | |
| created_at | datetime | YES | | NULL | |
| updated_at | datetime | YES | | NULL | |
| published_at | datetime | YES | | NULL | |
| category_id | int(11) | YES | | 1 | |
+--------------+--------------+------+-----+---------+----------------+
10 rows in set (0.01 sec)
Help?!
Bernard
Ps. hope the formatting of the table above holds up... doesn't seem to look very good in the preview!
Controller code for relevant call as follows.
def show
if is_logged_in? && @logged_in_user.has_role?('Editor')
@article = Article.find(params[:id])
else
@article = Article.find_all_by_published(params[:id], true)
end
respond_to do |wants|
wants.html
wants.xml { render :xml => @article.to_xml }
end
end