Feedback functionalities for ActiveRecord models
Add to Gemfile:
gem 'minimal_feedback'
Run:
bundle install
rails generate minimal_feedback
rake db:migrate
Let's say we have an Issue ActiveRecord model and we want to be able to give it feedback
class User < ActiveRecord::Base
has_many :issues
end
class Issue < ActiveRecord::Base
include MinimalFeedback
attr_accessor :condition
allow_feedback :if => proc { condition }
belongs_to :user
end
What would happen with this configuration:
issue = Issue.create
issue.condition = true
issue.give_feedback(:positive)
issue.feedbacks.first.type
=> :positive
issue.give_feedback(:negative)
issue.feedbacks.last.type
=> :negative
If the condition proc returns false when the give_feedback method is called an ActiveRecord invalid exception is raised.
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request