Rails заслуживает драгоценного камня, не работающего в моем приложении rails 4.1
В Merit.rb
Merit.setup do |config|
# Check rules on each request or in background
config.checks_on_each_request = true
config.orm = :active_record
# Add application observers to get notifications when reputation changes.
# config.add_observer 'MyObserverClassName'
config.user_model_name = 'User'
config.current_user_method = 'current_user'
end
badge_id = 0
[{
id: (badge_id = badge_id+1),
name: 'commenter',
description: 'You\'ve participated good in our boards! (level 10)',
level: 10
}, {
id: (badge_id = badge_id+1),
name: 'autobiographer',
description: 'You\'ve edited your name and it\'s above 4 characters! (?)'
}].each do |badge|
Merit::Badge.create! badge
end
В badge_rules.rb
grant_on 'comments#create', badge: 'commenter', level: 10 do |comment|
comment.user.comments.count >= 10
end
grant_on 'users/registrations#update', badge: 'autobiographer', temporary: true, model_name: 'User' do |user|
user.name.length > 4
end
И на мой взгляд, у меня есть другая страница для отображения значков current_user.badges
Смотрите sql для вставки sashe в ambry db.
Это когда я создаю комментарий, я думаю, что это нормально.
0.3ms) BEGIN
SQL (0.5ms) INSERT INTO "merit_actions" ("action_method", "created_at", "target_id", "target_model", "updated_at", "user_id") VALUES ($1, $2, $3, $4, $5, $6) RETURNING "id" [["action_method", "create"], ["created_at", "2014-08-12 13:50:13.495261"], ["target_id", 46], ["target_model", "comments"], ["updated_at", "2014-08-12 13:50:13.495261"], ["user_id", 2]]
(2.8ms) COMMIT
Merit::Action Load (0.5ms) SELECT "merit_actions".* FROM "merit_actions" WHERE "merit_actions"."processed" = 'f'
(0.3ms) BEGIN
SQL (0.4ms) UPDATE "merit_actions" SET "processed" = $1, "updated_at" = $2 WHERE "merit_actions"."id" = 10 [["processed", "t"], ["updated_at", "2014-08-12 13:50:13.501569"]]
(4.6ms) COMMIT
Comment Load (0.8ms) SELECT "comments".* FROM "comments" WHERE "comments"."id" = 46 LIMIT 1
User Load (0.5ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT 1 [["id", 2]]
(0.3ms) SELECT COUNT(*) FROM "comments" WHERE "comments"."user_id" = $1 [["user_id", 2]]
User Load (0.5ms) SELECT "users".* FROM "users" WHERE "users"."id" = 2 LIMIT 1
(0.3ms) BEGIN
SQL (0.4ms) INSERT INTO "sashes" ("created_at", "updated_at") VALUES ($1, $2) RETURNING "id" [["created_at", "2014-08-12 13:50:13.517458"], ["updated_at", "2014-08-12 13:50:13.517458"]]
SQL (0.4ms) INSERT INTO "merit_scores" DEFAULT VALUES RETURNING "id"
SQL (0.4ms) UPDATE "merit_scores" SET "sash_id" = $1 WHERE "merit_scores"."id" = 7 [["sash_id", 7]]
(10.4ms) COMMIT
(0.3ms) BEGIN
User Exists (0.7ms) SELECT 1 AS one FROM "users" WHERE ("users"."email" = 'bharanidharan@railsfactory.org' AND "users"."id" != 2) LIMIT 1
User Exists (0.5ms) SELECT 1 AS one FROM "users" WHERE (LOWER("users"."username") = LOWER('bharani') AND "users"."id" != 2) LIMIT 1
(0.2ms) ROLLBACK
Merit::BadgesSash Load (0.4ms) SELECT "badges_sashes".* FROM "badges_sashes" WHERE "badges_sashes"."sash_id" = $1 [["sash_id", 7]]
(0.2ms) BEGIN
SQL (0.6ms) INSERT INTO "badges_sashes" ("badge_id", "created_at", "sash_id") VALUES ($1, $2, $3) RETURNING "id" [["badge_id", 1], ["created_at", "2014-08-12 13:50:13.541865"], ["sash_id", 7]]
(5.6ms) COMMIT
(0.3ms) BEGIN
SQL (0.4ms) INSERT INTO "merit_activity_logs" ("action_id", "created_at", "description", "related_change_id", "related_change_type") VALUES ($1, $2, $3, $4, $5) RETURNING "id" [["action_id", 10], ["created_at", "2014-08-12 13:50:13.551158"], ["description", "granted commenter badge"], ["related_change_id", 5], ["related_change_type", "Merit::BadgesSash"]]
Это когда я запрашиваю просмотр страницы, он снова вставляет пояс, который я не знаю, почему.
SQL (0.4ms) INSERT INTO "sashes" ("created_at", "updated_at") VALUES ($1, $2) RETURNING "id" [["created_at", "2014-08-12 13:51:55.001496"], ["updated_at", "2014-08-12 13:51:55.001496"]]
SQL (0.6ms) INSERT INTO "merit_scores" DEFAULT VALUES RETURNING "id"
SQL (0.5ms) UPDATE "merit_scores" SET "sash_id" = $1 WHERE "merit_scores"."id" = 8 [["sash_id", 8]]
(19.0ms) COMMIT
(0.3ms) BEGIN
User Exists (0.5ms) SELECT 1 AS one FROM "users" WHERE ("users"."email" = 'bharanidharan@railsfactory.org' AND "users"."id" != 2) LIMIT 1
User Exists (0.8ms) SELECT 1 AS one FROM "users" WHERE (LOWER("users"."username") = LOWER('bharani') AND "users"."id" != 2) LIMIT 1
(0.4ms) ROLLBACK
Merit::BadgesSash Load (0.4ms) SELECT "badges_sashes".* FROM "badges_sashes" WHERE "badges_sashes"."sash_id" = $1 [["sash_id", 8]]
Rendered badges/my_badges.html.erb within layouts/application (37.4ms)
Всегда user.sashe_id не получает обновления всякий раз, когда я вижу после вызова badge_rules. Если я назначу user.sashe_id через консоль, он будет работать нормально.
Пожалуйста, поймите меня, где я не прав. Спасибо