1 min read

Rails, sqlite3, and id=0

I’ve spent the last few days struggling with a problem with Plantae’s rails code. I was certain that code like this should work:

class ContentController < ApplicationController
  def new
    @plant = Plant.new(params[:plant])
    if request.post? and @plant.save
      redirect_to :action => 'show', :id => @plant.id

  def show
    @plant = Plant.find(params[:id])

These statements should create a new plant and then redirect to the show method which sends the newly created plant to the view.

The problem was that rails insisted on asking sqlite3 for the plant with id=0, which cannot exist.

After a post to the rails mailing list and some thorough diagnostics I discovered this and realized I needed swig.

So, if anyone else has this problem:

sudo port install swig
sudo gem install sqlite3-ruby

is the solution.