0

I am trying to follow a tutorial from Adding a 5 star ratings feature to a Rails 4 model made by @Simpleton and I cannot successfully create the model for the tutorial.

When I type rails g model Rating comment:references user:references score:integer default: 0 it will create the model. When I run rake db:migrate I receive an error message which says:

/db/migrate/20140107143726_create_ratings.rb:8: syntax error, unexpected tINTEGER, expecting tSTRING_CONTENT or tSTRING_DBEG or tSTRING_DVAR or tSTRING_END

What can I do? Is there a different way to set the default value for the integer named "score"?

Update

In "db/migrate/20140107143726_create_ratings.rb" I have:

class CreateRatings < ActiveRecord::Migration
  def change
    create_table :ratings do |t|
      t.references :review, index: true
      t.references :user, index: true
      t.integer :score
      t.string :default
      t.string :0

      t.timestamps
    end
  end
end

*I changed comment to review

Would this work?

class CreateRatings < ActiveRecord::Migration
  def change
    create_table :ratings do |t|
      t.references :review, index: true
      t.references :user, index: true
      t.integer :score, :default => 0

      t.timestamps
    end
  end
end

based on Example1, and Example 2.

Community
  • 1
  • 1
Daniel
  • 2,950
  • 2
  • 25
  • 45

1 Answers1

0

There's an issue in your /db/migrate/20140107143726_create_ratings.rb migration.

Make sure that the score line in there looks something like:

add_column :ratings, :score, :integer, default: 0

UPDATE

Yes, this example should work:

class CreateRatings < ActiveRecord::Migration
  def change
    create_table :ratings do |t|
      t.references :review, index: true
      t.references :user, index: true
      t.integer :score, :default => 0

      t.timestamps
    end
  end
end
CDub
  • 13,146
  • 4
  • 51
  • 68
  • Okay I updated my question. Im not sure the proper way to correct the _create_ratings.rb file. – Daniel Jan 07 '14 at 15:10