SimplyDope
SimplyDope

Reputation: 67

Save works when using SQLite but not on Heroku's Postgresql

In my app, I'm able to save the user_id on my development machine using sqlite. However, the user_id is not being saved on my Heroku site, which uses 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

The user must be signed in to add a review. Should I be saving the user_id a different way?

Upvotes: 0

Views: 176

Answers (1)

mu is too short
mu is too short

Reputation: 434795

Here's a wild guess: you have a string column in Review that has a limit and you're exceeding that limit when you say @product.reviews.build(params[:review]). SQLite doesn't pay attention to size limits on varchar columns, PostgreSQL does and complains if you try to insert a value that is larger than the column size.

And some advice for free: don't develop on SQLite if you're going to deploy to Heroku (or anywhere else that doesn't use SQLite), all databases are different and no ORM will protect you from those differences.

Upvotes: 1

Related Questions