views:

33

answers:

1

This is the error I get:

ContactPostalcardsController#skip (NoMethodError) "undefined method `status=' for #<ContactPostalcard:0x2b21433d64b0>"

This is the code calling it and trying to assign a value to the status attribute for ContactPostalcard (the Model):

  def skip

    @contact_postalcard = ContactPostalcard.new(params[:contact_postalcard])
    @contact_postalcard.contact_id = params[:contact_id]
    @contact_postalcard.postalcard_id = params[:postalcard_id]

    @contact_postalcard.status = "skipped"
    @contact_postalcard.date_sent = Date.today
    @contact_postalcard.date_created = Date.today

    if @contact_postalcard.save
      render :text => 'This email was skipped!'

    end
  end 

This is the Model referred. Note the "annotate" output shows status as an attribute:

class ContactPostalcard < ActiveRecord::Base
  attr_accessible :title, :contact_id, :postal_id, :postalcard_id, :message, :campaign_id, :date_sent, :status


  belongs_to :contact
  belongs_to :postalcard

  alias_attribute :body, :message
  alias_attribute :subject, :title 

  named_scope :nosugar, :conditions => { :sugarcrm => false }

  def company_name
    contact = Contact.find_by_id(self.contact_id)

    return contact.company_name

  end 

  def asset
    Postalcard.find_by_id(self.postalcard_id)
  end

  def asset_class
    Postalcard.find_by_id(self.postalcard_id).class.name
  end  

end



# == Schema Information
#
# Table name: contact_postalcards
#
#  id            :integer         not null, primary key
#  title         :string(255)
#  contact_id    :integer
#  postalcard_id :integer
#  message       :text
#  campaign_id   :integer
#  date_sent     :datetime
#  created_at    :datetime
#  updated_at    :datetime
#  postal_id     :integer
#  sugarcrm      :boolean         default(FALSE)
#  status        :string(255)
#

I am unclear as to why I keep getting an 'undefined method' -- I have added the status attribute (it had been missing before but used a migration and then raked), so need some help...thank you.

+1  A: 

Have you restarted your Rails application since you ran your migration? If you're running in production mode, Rails caches your classes until you restart it, and since status wasn't an attribute before the migration, Rails wouldn't have added accessor methods for it, which would explain why status= is undefined.

Daniel Vandersluis
Hmmm...I did a 'heroku restart' command and I am still getting the error....
Angela
although this was just part of the problem, it was something I needed to lead to the ultimate solution and as a practice altogether.
Angela