I am getting following error:
##################################################
NoMethodError in TopicsController#show
You have a nil object when you didn't expect it!
The error occurred while evaluating nil.items
##################################################

####################
## Show Method in topics controller
####################
def show
  @topic = @object
  @items = @topic.items
end


####################
##Topic Model
####################
class Topic < ActiveRecord::Base
  validates_presence_of :title, :section_id
  validates_uniqueness_of :title
  has_many :items
    :order => :position,
    :dependent => :destroy, #don't leave orphans (delete my children)
    :conditions =>"parent_id is null" #
    belongs_to :section
end

####################
##Item Model
####################

class Item < ActiveRecord::Base
  validates_uniqueness_of :title, :scope => [:topic_id, :parent_id]
  validates_presence_of :topic_id, :title, :owner, :position

  belongs_to :topic
  belongs_to :parent,
    :class_name => "Item",
    :foreign_key => "parent_id"
  has_many :children,
    :class_name => "Item",
    :foreign_key => "parent_id",
    :order => :position,
    :dependent => :destroy #don't leave orphans (cascade delete)
  has_many :attachments,
    :dependent => :destroy #don't leave orphans (cascade delete)

  def section
    self.topic ? self.topic.section : nil
  end
end
####################


In addition, I have Items controller and attachments controller. Right
now I am starting with first Topics controller only. My config/routes.rb
file contains:
  map.resources :topics
. I would like to make this application RESTful.

Any ideas on how to proceed and resolve this error?

Thanks,
CS.
-- 
Posted via http://www.ruby-forum.com/.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to