2011-10-31 35 views
0

在我的應用程序中,我可以使用sqlite將user_id保存在我的開發計算機上。但是,user_id並未保存在使用Postgresql的Heroku站點上:保存使用SQLite但不在Heroku的Postgresql上的作品

class ReviewsController < ApplicationController 

    before_filter :authenticate_user!, :find_product 

    def new 
    @review = Review.new  
    end 

    def create 
    @review = @product.reviews.build(params[:review]) 
    @review.user_id = current_user.id 
    if @review.save 
     SiteUpdatesMailer.review_added(@review).deliver 
     redirect_to product_path(@product), :notice => 'Thanks for your review!'  
    else 
     render :action => :new  
    end 
    end 

    private 

    def find_product 
    @product = Product.find(params[:product_id])  
    end 

end 

用戶必須登錄才能添加評論。我應該以不同的方式保存user_id嗎?

回答

1

這是一個瘋狂的猜測:您在Review中有一個字符串列,它有一個限制,當你說@product.reviews.build(params[:review])時,你超過了這個限制。 SQLite不關注varchar列的大小限制,如果您嘗試插入大於列大小的值,PostgreSQL會提出並抱怨。

還有一些免費的建議:如果你打算部署到Heroku(或其他不使用SQLite的地方),不要在SQLite上開發,所有的數據庫都是不同的,沒有ORM可以保護你免受這些差異。

+0

AAARrrrrggghh。好的,這個代碼實際上起作用。檢查Heroku登錄應用程序和助手功能正在炸燬。我會考慮在我的測試機器上運行Postgresql。 – SimplyDope

相關問題