0

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?

0

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

AAARrrrrggghh. Ok, this code actually works. Checked Heroku logs on app and a function in a helper was blowing up. I will look into running Postgresql on my test machine though.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.