Search code examples
ruby-on-railsrating

Integrate acts_as_rated plugin in rails application


I am creating a user-boards applicationin rails in which a user owns any number of boards and can rate the boards.I want to install acts_as_rated plugin in my rails application. Since this is not available as a gem i have used following command to install it as a plugin:

rails plugin install svn://rubyforge.org/var/svn/acts-as-rated/trunk/acts_as_rated

This command installs all required plugin files in the vendor directory. Next I include the following code in my Boards model

class Board < ActiveRecord::Base
  acts_as_rated
end

Next i restart my console and run the following commands

u=User.first
 => #<User id: 1, first_name: "taroon", created_at: "2012-03-26 09:18:20", updated_at: "2012-03-26 09:18:20">

b=Board.first
 => #<Board id: 1, name: "boards_1", created_at: "2012-03-26 09:19:39", updated_at: "2012-03-26 09:19:39"> 

b.rate 5, u

It gives me the following error

ActiveRecord::StatementInvalid: Could not find table 'ratings'
from /home/swati/.rvm/gems/ruby-1.9.2-p318/gems/activerecord-3.0.10/lib/active_record/connection_adapters/sqlite_adapter.rb:295:in `table_structure'
from /home/swati/.rvm/gems/ruby-1.9.2-p318/gems/activerecord-3.0.10/lib/active_record/connection_adapters/sqlite_adapter.rb:186:in `columns'
from /home/swati/.rvm/gems/ruby-1.9.2-p318/gems/activerecord-3.0.10/lib/active_record/base.rb:685:in `columns'
from /home/swati/.rvm/gems/ruby-1.9.2-p318/gems/activerecord-3.0.10/lib/active_record/base.rb:698:in `column_names'
from /home/swati/projects/test_projects/dummy_project/vendor/plugins/acts_as_rated/lib/acts_as_rated.rb:193:in `rate'
from (irb):6
from /home/swati/.rvm/gems/ruby-1.9.2-p318/gems/railties-3.0.10/lib/rails/commands/console.rb:44:in `start'
from /home/swati/.rvm/gems/ruby-1.9.2-p318/gems/railties-3.0.10/lib/rails/commands/console.rb:8:in `start'
from /home/swati/.rvm/gems/ruby-1.9.2-p318/gems/railties-3.0.10/lib/rails/commands.rb:23:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'

I checked out the migartion but no migration for rating tables was created. Neither I have an idea of the fields in this table.

Can anyone please suggest me a solution for this problem..


Solution

  • The README of act_as_rated plugin says that you need to do your own migration based on this file: test/fixtures/migrations/001_add_rating_tables.rb.

    Quote from the README:

    The file test/fixtures/migrations/001_add_rating_tables.rb shows examples of all types of migration options.

    See also the detailed documentation for the acts_as_rated method on how to declare it, and the rest of the documentation for how to generate the migration columns/files and how to use it.

    So download and extract your module from here, then you can find the corresponding file and you can do your own migration.