Rolando Sotomayor
2011-Nov-02 16:05 UTC
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: <strong>Date Posted:</strong> <%distance_of_time_in_words_to_now(@classified.created_at) %> ago <br /> 16: 17: <strong>Last updated:</strong> <%distance_of_time_in_words(@classified.updated_at, Time.now) %> ago </p> 18: <p><%= @classified.description %></p> 19: 20: <hr/> 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"} -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Colin Law
2011-Nov-02 16:25 UTC
Re: undefined method `updated_at'' for #<Classified:0x686c5e4>
On 2 November 2011 16:05, Rolando Sotomayor <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> 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>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 -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Rolando Sotomayor
2011-Nov-02 16:56 UTC
Re: undefined method `updated_at'' for #<Classified:0x686c5e4>
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 <html> <head> <title>Mostrar items</title> </head> <body> <h1><%= @classified.title %></h1> <p><strong>Price: </strong> <%= number_to_currency(@classified.price)%> <br /><br /> <% if not @classified.category.blank? %> <strong>Category: </strong> <%= link_to @classified.category.name,:controller => "category", :action => "show",:id => @classified.category.id %><br /> <% end %> <strong>Location: </strong> <%= @classified.location %> <br /> <strong>Date Posted:</strong> <%= distance_of_time_in_words_to_now(@classified.created_at) %> ago <br /> <strong>Last updated:</strong> <%= distance_of_time_in_words(@classified.updated_at, Time.now) %> ago </p> <p><%= @classified.description %></p> <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'')") %></p> <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" -%><br /> Message: <br /> <%= text_area "contact", "message", {:rows => 10} -%><br /> <%= submit_tag ''Contact seller'' -%> <%= end_form_tag -%> </div> <%= link_to ''Back'', home_url %> </body> </html> ------------------------------------- -> 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 -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Colin Law
2011-Nov-02 17:22 UTC
Re: Re: undefined method `updated_at'' for #<Classified:0x686c5e4>
On 2 November 2011 16:56, Rolando Sotomayor <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> 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 -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Dave Aronson
2011-Nov-02 17:42 UTC
Re: undefined method `updated_at'' for #<Classified:0x686c5e4>
On Wed, Nov 2, 2011 at 12:05, Rolando Sotomayor <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> 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) -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.