I've put together a simple app, when run displays the error below. Anyone know why the instance variable (@news_form) is nil? See below for my controller and view code. Thanks.
Controller:You have a nil object when you didn't expect it!
You might have expected an instance of ActiveRecord::Base.
The error occurred while evaluating nil.update_attributes
View:Code:class NewsController < ApplicationController def add_news @news_form = News.new end def save_news @news_form.update_attributes(params[:news_form]) if @news_form.save redirect_to :action => "news" else render :action => "add_news" end end end
Code:<%= error_messages_for :news_form %> <h1>Add News</h1> <%- form_for @news_form, :url => { :action => :save_news } do |f| -%> <fieldset> <legend>Enter News Details</legend> <%= f.label :title, "Title:" %> <%= f.text_field :title %> <br /> <%= f.label :description, "Description:" %> <%= f.text_area :description %> </p> <p><%= f.submit "Add" %></p> <%- end -%> <%= link_to "View News", :action => "news" %> </fieldset>






rder => "id DESC"
Bookmarks