views:

6

answers:

0

I created a model that had a string primary_key.

The Create action in Ruby on Rails gave me the following error:

Couldn't find Theme with ID=0

My Theme table has no ID column, but a string column called name which is the primary key.

After searching everywhere, I experimented myself with the Create action inside the theme_controller.

It initially was:

def create
    @theme = Theme.new(params[:theme])

    respond_to do |format|
      if @theme.save
    ....

The :name parameter was being correctly passed, but was not being used, it was being replaced by an ID which my model does not have.

The solution was to insert the following line to force RoR to take the name into the object.

def create
    @theme = Theme.new(params[:theme])
    @theme.name = params[:theme][:name]
    respond_to do |format|
      if @theme.save
    ....