Undefined method `updated_at' for #<Classified:0x686c5e4>

HEllo, I have the following problem with rails, I am new in this…is
there anyone who explain to me what´s happens?
Thanks
See below:

NoMethodError in Classified#show
Showing app/views/classified/show.rhtml where line #17 raised:

undefined method `updated_at’ for #Classified:0x686c5e4

Extracted source (around line #17):

14:
15: Date Posted: <%=
distance_of_time_in_words_to_now(@classified.created_at) %> ago

16:
17: Last updated: <%=
distance_of_time_in_words(@classified.updated_at, Time.now) %> ago


18:

<%= @classified.description %>


19:
20:

RAILS_ROOT: ./script/…/config/…

Application Trace | Framework Trace | Full Trace
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/base.rb:1792:in
`method_missing’
#{RAILS_ROOT}/app/views/classified/show.rhtml:17:in

Request
Parameters: {“id”=>“19”}

Show session dump


flash: !map:ActionController::Flash::FlashHash {}

Response
Headers: {“cookie”=>[], “Cache-Control”=>“no-cache”}

On 2 November 2011 16:05, Rolando S. [email protected]
wrote:

undefined method `updated_at’ for #Classified:0x686c5e4
Has the classifieds table got a column updated_at? Show us the bit of
db/schema.rb for that table if you think it has.

Post the start of classified.rb showing the class definition and any
other stuff before the methods (if any).

Colin

On 2 November 2011 16:56, Rolando S. [email protected]
wrote:

I have these tables on my database with these fields each one:

->classifieds:(id,title,location,description,email,create_at,updated_at,category_id,content_type,picture)

I presume you just typed that and have mistyped. That is why I asked
for schema.rb. Copy/paste in order to avoid typos.

What happens if you run the rails console and do
c = Classified.first
Does it show update_at

Colin

I have these tables on my database with these fields each one:

->classifieds:(id,title,location,description,email,create_at,updated_at,category_id,content_type,picture)

->categories(id,name)

This is what I have in the followings files:

->classified_controller.rb
class ClassifiedController < ApplicationController
layout ‘standard’

def list
@classifieds = Classified.find(:all)
end

def show
@classified = Classified.find(params[:id])
end

def new
@classified = Classified.new
@categories = Category.find(:all)
end

def create
@classified = Classified.new(params[:classified])
@categories = Category.find(:all)
if @classified.save
redirect_to home_url
else
render :action => ‘new’
end
end

def edit
@classified = Classified.find(params[:id])
@categories = Category.find(:all)
end

def update
@classified = Classified.find(params[:id])
@categories = Category.find(:all)
if @classified.update_attributes(params[:classified])
flash[:notice] = ‘Classified was successfully updated.’
redirect_to :action => ‘show’, :id => @classified
else
render :action => ‘edit’
end
end

def delete
Classified.find(params[:id]).destroy
redirect_to :action => ‘list’
end
end


->category_controller.rb
class CategoryController < ApplicationController
layout ‘standard’

def list
    @categories = Category.find(:all)
end

def show
    @category = Category.find(params[:id])
end

def new
    @category = Category.new(params[:category])
    if @category.save
    return if request.xhr?
    render :partial => 'category', :object => @category
    end
end

def delete
    @category = Category.find(params[:id])
    @category.destroy
    return if request.xhr?
    render :nothing, :status => 200
end

end

-> app/views/classified/show.rhtml

Mostrar items

<%= @classified.title %>

Price: <%= number_to_currency(@classified.price)%>

<% if not @classified.category.blank? %>
<strong>Category: </strong> <%= link_to 

@classified.category.name,:controller => “category”, :action =>
“show”,:id => @classified.category.id %>

<% end %>

<strong>Location: </strong> <%= @classified.location %> <br />

<strong>Date Posted:</strong> <%= 

distance_of_time_in_words_to_now(@classified.created_at) %> ago

<strong>Last updated:</strong> <%= 

distance_of_time_in_words(@classified.updated_at, Time.now) %> ago


<%= @classified.description %>

<hr/>

<% unless @classified.picture.blank? %>
<%= image_tag(url_for({:action => 'image', :id => @classified.id})) 

-%>
<% end %>

<p>Interested? <%= link_to_function('Contact the 

seller’,“Element.show(‘contact_seller’)”) %>

<div id="contact_seller" style="display:none;">
<%= form_remote_tag(:url => {:action => 'contact',:id => 

@classified.id },:html => {:id => “contact_form”}) -%>
Your e-mail: <%= text_field “contact”, “email” -%>

Message:

<%= text_area “contact”, “message”, {:rows => 10} -%>

<%= submit_tag ‘Contact seller’ -%>

<%= end_form_tag -%>
</div>

<%= link_to 'Back', home_url %>

-> app/models/classified.rb
class Classified < ActiveRecord::Base
belongs_to :category
validates_presence_of :title, :message => “cannot be blank. Make your
title descriptive”
validates_presence_of :price, :message => “must be a numeric, value
(do not include a dollar sign)”
validates_presence_of :location
validates_presence_of :description
validates_presence_of :email

validates_numericality_of :price

protected
def validate
errors.add(:price, “should be a positive value”) if price.nil?||
price < 0.01
end
validates_format_of :email,:with =>
/^([^@\s]+)@((?:[-a-z0-9]+.)+[a-z]{2,})$/i

def pictureimg=(picture_field)
return if picture_field.blank?
self.content_type = picture_field.content_type.chomp
self.picture = picture_field.read
end
end

->db/migrate/001_create_classifieds.rb

class CreateClassifieds < ActiveRecord::Migration
def self.up
create_table :classifieds do |t|
# t.column :name, :string
t.column :title, :string
t.column :price, :float
t.column :location, :string
t.column :description, :text
t.column :email, :string
t.column :created_at, :timestamp
t.column :updated_at, :timestamp
end
end

def self.down
drop_table :classifieds
end
end

->db/migrate/002_create_categories.rb

class CreateCategories < ActiveRecord::Migration
def self.up
create_table :categories do |t|
# t.column :name, :string
t.column :name, :string
end
Category.create :name => “Electronics”
Category.create :name => “Real Estate”
Category.create :name => “Furniture”
Category.create :name => “Miscellaneus”

add_column :classifieds, :category_id, :integer
Classified.find(:all).each do |c|
  c.update_attribute(:category_id, 4)
  end

end

def self.down
drop_table :categories
end
end

I hope this is enough
Thanks

On Wed, Nov 2, 2011 at 12:05, Rolando S. [email protected]
wrote:

undefined method `updated_at’ for #Classified:0x686c5e4

If “updated_at” was a column you manually specified, I recommend you
rename it. That name is used automagically by Rails behind the
scenes, so using it manually is asking for trouble. That and
created_at are the timestamps added to any generated migration that
creates a new table.

Or are you actually trying to use the automagic one? The details were
“tl;dr”, but if you really need, I can slog through them…

-Dave


LOOKING FOR WORK! What: Ruby (on/off Rails), Python, other modern
languages.
Where: Northern Virginia, Washington DC (near Orange Line), and remote
work.
See: davearonson.com (main) * codosaur.us (code) * dare2xl.com
(excellence).
Specialization is for insects. (Heinlein) - Have Pun, Will Babble!
(Aronson)