views:

343

answers:

5

Ok so got through my last problem with the difference between Postgresql and SQLite and seems like Heroku is telling me I have another one. I am new to ruby and rails so a lot of this stuff I can't decipher at first. Looking for a little direction here. The error message and PostsController Index are below. I checked my routes.rb file and all seems well there but I could be missing something. I will post if you need.

Processing PostsController#index (for 99.7.50.140 at 2010-04-23 15:19:22) [GET]

ActiveRecord::StatementInvalid (PGError: ERROR:  relation "tags" does not exist
:             SELECT a.attname, format_type(a.atttypid, a.atttypmod), d.adsrc, a.attnotnull
              FROM pg_attribute a LEFT JOIN pg_attrdef d
                ON a.attrelid = d.adrelid AND a.attnum = d.adnum
             WHERE a.attrelid = '"tags"'::regclass
               AND a.attnum > 0 AND NOT a.attisdropped
             ORDER BY a.attnum
):

PostsController#index

  def index
    @tag_counts = Tag.count(:group => :tag_name, 
       :order => 'count_all DESC', :limit => 20)
       conditions, joins = {}, :votes

    @ugtag_counts = Ugtag.count(:group => :ugctag_name, 
       :order => 'count_all DESC', :limit => 20)
       conditions, joins = {}, :votes

    @vote_counts = Vote.count(:group => :post_title, 
          :order => 'count_all DESC', :limit => 20)
          conditions, joins = {}, :votes


       unless(params[:tag_name] || "").empty?
         conditions = ["tags.tag_name = ? ", params[:tag_name]]
         joins = [:tags, :votes]
       end
       @posts=Post.paginate(
                 :select => "posts.*, count(*) as vote_total", 
                 :joins => joins, 
                 :conditions=> conditions, 
                 :group => "votes.post_id, posts.id ", 
                 :order => "created_at DESC",
                 :page => params[:page], :per_page => 5)
        @popular_posts=Post.paginate(
                 :select => "posts.*, count(*) as vote_total", 
                 :joins => joins, 
                 :conditions=> conditions, 
                 :group => "votes.post_id, posts.id", 
                 :order => "vote_total DESC",
                 :page => params[:page], :per_page => 3)

    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @posts }
      format.json { render :json => @posts }
      format.atom
    end
  end
+1  A: 

This looks strange:

WHERE a.attrelid = '"tags"'::regclass

The single quotes delimit a string literal, so the inner double-quotes are treated as part of the string. So it's looking for a table name that actually has " characters as part of the name.

I'm not sure how the Rails plumbing has generated that query, so I don't have anything to suggest to fix it. Sorry...

But this definitely seems to be a Leaky Abstraction problem. :-)

Bill Karwin
That isn't very comforting. Don't really understand all that is in the link you provided. I def don't have a table with " in it as I don't even think that is possible. Hopefully someone else has seen this before. I'm new to ruby, rails, and programming in general so this is tough stuff for me.
bgadoci
Normally Rails infers the name of the table from your ActiveRecord class names, but this can be overridden. Perhaps you've specified the SQL table name somewhere and accidentally included " characters?
Bill Karwin
A: 

What all gems are used by this Rails app? Do you have a .gems manifest file in the root of the app for heroku to auto detect and install? i see that you are using will paginate gem. If you haven't added the gems to the .gems file then i guess thats the trouble. If you haven't done that then this would be the best place to look for help: Heroku | Managing Gems

Shripad K
I am using will_paginate, paperclip, wysihat-engine. They all have lines in the environment.rb file. Isn't the environment.rb file where heroku looks to auto install this stuff?
bgadoci
Oops! No. Heroku won't auto detect from the environment.rb file. You need a special .gems manifest file in the root of your app. Create one, and add all your gems in it. The procedure is described in the link above. I guess with that all your problems with heroku stands solved. :)
Shripad K
A: 

I just discovered the source of this issue in my rails app, thanks to Bill Karwin's tip above:

When I update my db schema by running rake db:schema:dump on my dev box, it replaces some (but not all) symbols with enquoted strings...

e.g.,

add_index :taggings, ["vectors"] 

becomes

add_index "taggings", ["vectors"] 

This doesn't cause any problems on my dev box, but heroku doesn't seem to handle the discrepancy well when the db is created from scratch, but not on a db:push.

As soon as I manually switched the table names symbols, my app started playing nice again.

If anyone knows the reason for this offhand, I'd be interested...

soychicka
A: 

I have the same problem. I bet ur table name must be 'tag', not 'tags'. If you change ur table name to 'tags' in Postgresql, it'll work. But why? I gave the singular model name, GHOST takes the plural.

Sam
A: 

To add the line below to your /config/environment.rb:

ActiveRecord::Base.pluralize_table_names = false
Sam