Ruby on rails 3.2 Rails 3.2不工作
我已经阅读了所有关于美德宝石的最新问题和答案。并试图遵循这里给出的解决方案 初始化者/merit.rb:Ruby on rails 3.2 Rails 3.2不工作,ruby-on-rails-3.2,badge,merit-gem,Ruby On Rails 3.2,Badge,Merit Gem,我已经阅读了所有关于美德宝石的最新问题和答案。并试图遵循这里给出的解决方案 初始化者/merit.rb: # Use this hook to configure merit parameters Merit.setup do |config| # Check rules on each request or in background config.checks_on_each_request = true # Define ORM. Could be :active_recor
# Use this hook to configure merit parameters
Merit.setup do |config|
# Check rules on each request or in background
config.checks_on_each_request = true
# Define ORM. Could be :active_record (default) and :mongo_mapper and :mongoid
config.orm = :active_record
# Define :user_model_name. This model will be used to grand badge if no :to option is given. Default is "User".
config.user_model_name = "User"
# Define :current_user_method. Similar to previous option. It will be used to retrieve :user_model_name object if no $
config.current_user_method = "current_user"
end
# Create application badges (uses https://github.com/norman/ambry)
# Merit::Badge.create!(
badges = [
{ id: 1, name: 'democratic-society', description: "Voted twice", image: "straight.jpg" }
]
badges.each do |badge|
Merit::Badge.create!(badge)
end
但经过3个小时的努力,我一无所获。我有一个徽章列在窗框中,我的用户有一个窗框id徽章,但窗框返回空集。。。但当我尝试以下代码时:
application.html.erb:
<% current_user.badges.each do |badge| %>
<%= badge.name %>
<%= badge.description %>
<%= image_tag (badge.image) %>
<% end %>
没有任何错误消息。。。所以我有点不知所措,不知下一步该怎么办。我甚至不能让它显示徽章的名字。任何帮助都将不胜感激。我看不到任何东西
posts_controller.rb:
class PostsController < InheritedResources::Base
before_filter :authenticate_user!, only: [:vote_up]
def index
if params[:query].present?
@posts = Post.tire.search(:query => params[:query])
else
@posts = Post.order("created_at desc").paginate(:page => params[:page], :per_page => 15)
end
end
def vote_up
begin
current_user.vote_for(@post = Post.find(params[:id]))
flash[:success] = "Thanks for voting! Be sure to come back to find out the winners!"
redirect_to [@post]
rescue ActiveRecord::RecordInvalid
flash[:error] = "You have already voted on this one. You're only allowed one vote per song."
redirect_to [@post]
end
end
end
徽章是用户的徽章列表和徽章本身之间的关系。为使其发挥作用,应在徽章和肩带中插入一个插件。控制器动作看起来如何?你能把完整的Rails日志放在这里吗?好的。添加了控制器和action.Cool的日志。首先,在grant_on call中,您不需要阻止,因为它应该始终计算为true。您可以省略它,只在“postsvote_up”上留下grant_,:badge=>“democratic society”,:to=>:user.do@post.user是否返回您要授予徽章的用户?您使用的是哪个版本的优点?你能发布你整个merit.rb文件的内容吗?
class PostsController < InheritedResources::Base
before_filter :authenticate_user!, only: [:vote_up]
def index
if params[:query].present?
@posts = Post.tire.search(:query => params[:query])
else
@posts = Post.order("created_at desc").paginate(:page => params[:page], :per_page => 15)
end
end
def vote_up
begin
current_user.vote_for(@post = Post.find(params[:id]))
flash[:success] = "Thanks for voting! Be sure to come back to find out the winners!"
redirect_to [@post]
rescue ActiveRecord::RecordInvalid
flash[:error] = "You have already voted on this one. You're only allowed one vote per song."
redirect_to [@post]
end
end
end
Processing by PostsController#vote_up as HTML
Parameters: {"authenticity_token"=>"SVWawkgb2hpkAJztuJjIKuIfRww/OjSAZAVpUqKeMOc=", "id"=>"243-worse-than-moe"}
User Load (1.3ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 5 LIMIT 1
Post Load (1034.1ms) SELECT `posts`.* FROM `posts` WHERE `posts`.`id` = 243 LIMIT 1
EXPLAIN (35.6ms) EXPLAIN SELECT `posts`.* FROM `posts` WHERE `posts`.`id` = 243 LIMIT 1
EXPLAIN for: SELECT `posts`.* FROM `posts` WHERE `posts`.`id` = 243 LIMIT 1
+----+-------------+-------+-------+---------------+---------+---------+-------+------+-------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+-------+---------------+---------+---------+-------+------+-------+
| 1 | SIMPLE | posts | const | PRIMARY | PRIMARY | 4 | const | 1 | |
+----+-------------+-------+-------+---------------+---------+---------+-------+------+-------+
1 row in set (0.04 sec)
(0.1ms) BEGIN
Vote Exists (99.0ms) SELECT 1 AS one FROM `votes` WHERE (`votes`.`voteable_id` = BINARY 243 AND `votes`.`voteable_type` = 'Post' AND `votes`.`voter_type` = 'User' AND `votes`.`voter_id` = 5) LIMIT 1
SQL (152.3ms) INSERT INTO `votes` (`created_at`, `updated_at`, `vote`, `voteable_id`, `voteable_type`, `voter_id`, `voter_type`) VALUES ('2014-01-09 15:23:45', '2014-01-09 15:23:45', 1, 243, 'Post', 5, 'User')
(390.5ms) COMMIT
Redirected to http://liquid-radio.com:3000/posts/243-worse-than-moe
(0.2ms) BEGIN
SQL (47.5ms) INSERT INTO `merit_actions` (`action_method`, `action_value`, `created_at`, `had_errors`, `processed`, `target_id`, `target_model`, `updated_at`, `user_id`) VALUES ('vote_up', NULL, '2014-01-09 15:23:47', 0, 0, 243, 'posts',
'2014-01-09 15:23:47', 5)
(76.0ms) COMMIT
Merit::Action Load (0.3ms) SELECT `merit_actions`.* FROM `merit_actions` WHERE `merit_actions`.`processed` = 0
(0.1ms) BEGIN
(160.6ms) UPDATE `merit_actions` SET `processed` = 1, `updated_at` = '2014-01-09 15:23:47' WHERE `merit_actions`.`id` = 13
(99.3ms) COMMIT
Post Load (0.1ms) SELECT `posts`.* FROM `posts` WHERE `posts`.`id` = 243 LIMIT 1
CACHE (0.0ms) SELECT `posts`.* FROM `posts` WHERE `posts`.`id` = 243 LIMIT 1
Completed 302 Found in 7214.0ms (ActiveRecord: 2337.7ms)