我正在使用acts_as_votable gem。
这是我投票时的日志:
Started PUT "/stories/11/vote" for 127.0.0.1 at 2013-10-09 15:50:58 +0800
Processing by StoriesController#vote as JSON
Parameters: {"id"=>"11"}
Story Load (0.6ms) SELECT "stories".* FROM "stories" WHERE "stories"."id" = $1 LIMIT 1 [["id", "11"]]
User Load (1.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = 14 ORDER BY "users"."id" ASC LIMIT 1
Persona Load (0.4ms) SELECT "personas".* FROM "personas" WHERE "personas"."id" = $1 LIMIT 1 [["id", 15]]
(0.4ms) SELECT COUNT(*) FROM "votes" WHERE "votes"."votable_id" = $1 AND "votes"."votable_type" = $2 AND "votes"."voter_id" = 15 AND "votes"."vote_scope" IS NULL AND "votes"."voter_type" = 'Persona' [["votable_id", 11], ["votable_type", "Story"]]
ActsAsVotable::Vote Load (3.4ms) SELECT "votes".* FROM "votes" WHERE "votes"."votable_id" = $1 AND "votes"."votable_type" = $2 AND "votes"."voter_id" = 15 AND "votes"."vote_scope" IS NULL AND "votes"."voter_type" = 'Persona' ORDER BY "votes"."id" ASC LIMIT 1 [["votable_id", 11], ["votable_type", "Story"]]
(0.2ms) BEGIN
(0.2ms) COMMIT
(0.3ms) SELECT COUNT(*) FROM "votes" WHERE "votes"."votable_id" = $1 AND "votes"."votable_type" = $2 [["votable_id", 11], ["votable_type", "Story"]]
(0.4ms) SELECT COUNT(*) FROM "votes" WHERE "votes"."votable_id" = $1 AND "votes"."votable_type" = $2 AND "votes"."vote_flag" = 't' AND "votes"."vote_scope" IS NULL [["votable_id", 11], ["votable_type", "Story"]]
(0.3ms) SELECT COUNT(*) FROM "votes" WHERE "votes"."votable_id" = $1 AND "votes"."votable_type" = $2 AND "votes"."vote_flag" = 'f' AND "votes"."vote_scope" IS NULL [["votable_id", 11], ["votable_type", "Story"]]
(0.3ms) BEGIN
(0.2ms) COMMIT
Completed 500 Internal Server Error in 34ms (Views: 1.6ms | ActiveRecord: 8.0ms)
这是我的 JS:
$('.story-vote-up').on("ajax:success", function(evt, data, status, xhr) {
console.log(data);
}).on("ajax:error", function(evt, data, status, xhr){
console.log(data);
});
和link_to:
<%= link_to 'Vote', vote_story_path(story), method: :put, remote: true %>
和我的控制器动作:
def vote
@story = Story.find(params[:id])
respond_to do |format|
if @story.liked_by default_persona
format.html { redirect_to @story, notice: 'Voted' }
format.json { render json: @story, status: :voted, location: @story }
else
format.html { redirect_to @story, notice: 'Error voting' }
format.json { render json: @story.errors, status: :unprocessable_entity }
end
end
end
我能够在我想要的响应中获取数据,但为什么状态为 500?