0
我有一個應用程序,我正在部署到Heroku。除了我的用戶模型的「顯示」操作之外,一切似乎都奏效。簡單的關聯在Heroku上不起作用
這裏是我的用戶模型代碼(什麼是相關的,反正)
class User < ActiveRecord::Base
attr_accessor :password
attr_accessible :username, :email, :password,
:password_confirmation, :confirmed,
:school_id, :graduation,
:admin, :stars, :credits, :school_name
has_many :uploads, :dependent => :destroy
belongs_to :school
has_many :downloads, :source => :user_id, :dependent => :destroy
has_many :comments, :dependent => :destroy
#VALIDATIONS OMITTED
#WARNING
before_create :encrypt_password
#PASSWORD ENCRYPTION METHOD OMITTED
#getter for school name
def school_name
school.name if school
end
#setter for school name (will create school if it didn't find one)
def school_name=(name)
self.school = School.find_by_name(name) unless name.blank?
end
def add_credits(num)
self.credits += num
end
def charge
self.credits -= 1
self.save(false)
end
def has_downloaded?(file)
@downloads = self.downloads.find(:all, :conditions => "upload_id = #{file.id}")
return (@downloads.length > 0)
end
private
#MORE PASSWORD ENCRYPTION LOGIC
end
這裏是我上傳的型號代碼:
class Upload < ActiveRecord::Base
default_scope :order => 'uploads.created_at DESC'
attr_protected :linked_file_name, :linked_content_type, :linked_size
attr_accessible :user_id, :stars, :ratings,
:semester, :professor, :year,
:description, :course_id, :school_id
after_save :set_course_school
belongs_to :user
belongs_to :school
belongs_to :course
has_many :downloads, :source => :upload_id, :dependent => :destroy
has_many :comments, :foreign_key => "file_id", :dependent => :destroy
#belongs_to :class
#paperclip
has_attached_file :linked,
:storage => :s3,
:s3_credentials => "#{RAILS_ROOT}/config/s3.yml",
:path => ":class/:id/:attachment/:basename.:extension"
#validations
validates :school_id, :presence => true
def update_rating
@comments = self.comments.all
if @comments.length > 0
@stars = 0
@comments.each do |comment|
@stars += comment.rating
end
self.stars = @stars
self.ratings = @comments.length
end
self.save(false)
end
def course_name
return [course.subject, course.course_code].join(' ') if course
end
def course_name=(name)
@split = name.split(' ', 2)
@subject = @split.first
@course_code = @split.last
@conditions = {
:subject => @subject,
:course_code => @course_code,
:school_id => self.school_id
}
self.course = Course.find(:first, :conditions => @conditions) || Course.create(@conditions)
end
def set_course_school
course.set_school
end
end
這裏是控制器動作:
def show
@user = User.find(params[:id])
@uploads = @user.uploads.all
@downloads = @user.downloads.all
end
Heroku似乎有一些問題與@user.uploads.all
聲明工作正常在本地,這裏是日誌給我的東西:
2011-12-29T21:57:07+00:00 app[web.1]: Started GET "https://stackoverflow.com/users/1" for 200.88.103.28 at 2011-12-29 13:57:07 -0800
2011-12-29T21:57:07+00:00 app[web.1]: Processing by UsersController#show as HTML
2011-12-29T21:57:07+00:00 app[web.1]: Parameters: {"id"=>"1"}
2011-12-29T21:57:07+00:00 app[web.1]: Completed in 10ms
2011-12-29T21:57:07+00:00 app[web.1]:
2011-12-29T21:57:07+00:00 app[web.1]: ActiveRecord::StatementInvalid (PGError: ERROR: operator does not exist: character varying = integer
2011-12-29T21:57:07+00:00 app[web.1]: : SELECT "uploads".* FROM "uploads" WHERE ("uploads".user_id = 1) ORDER BY uploads.created_at DESC):
2011-12-29T21:57:07+00:00 app[web.1]: ^
2011-12-29T21:57:07+00:00 app[web.1]: app/controllers/users_controller.rb:21:in `show'
2011-12-29T21:57:07+00:00 app[web.1]: HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.
2011-12-29T21:57:07+00:00 app[web.1]: LINE 1: ...ROM "uploads" WHERE ("uploads".user_id = 1) ORDER...
任何想法?我想這個解決方案非常簡單。有什麼奇怪的是,我有另一個Heroku部署的應用程序使用完全相同的用戶邏輯(有一個顯示頁面,可以獲取用戶的所有'帖子'),並且工作正常。代碼看起來幾乎相同...
我非常感謝解決這個問題。我希望我可以提供賞金,但是我在Android問題上用了大部分代幣。
這是答案,謝謝!這是由於某種原因投了一個字符串,一定是我的拼寫錯誤。 – 2011-12-29 22:26:47