Created
October 19, 2012 17:24
-
-
Save sirramongabriel/3919463 to your computer and use it in GitHub Desktop.
vote count: replacing boolean values with strings in post.rb and the server output.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Hear is the server output. I explicitly hit the upvote link for demo purposes. This is also the server output with the suggested edit of replacing boolean values with strings in my post.rb model for the method vote_total. As far as I can understand, no matter which link I select (up or down vote), the value starts properly but gets submitted as 0. | |
Here is my updated Post.rb model containing the vote_total method. | |
class Post < ActiveRecord::Base | |
attr_accessible :URL, :description, :is_link | |
has_many :comments, dependent: :destroy | |
has_many :votes, dependent: :destroy | |
def vote_total | |
votes.where(vote: "true").size - votes.where(vote: "false").size | |
# votes.increment_counter(:vote, :post_id) | |
end | |
end | |
WEBrick output... | |
Started POST "/posts/1/votes?vote=true" for 127.0.0.1 at 2012-10-19 13:19:56 -0400 | |
Connecting to database specified by database.yml | |
Processing by VotesController#create as JS | |
Parameters: {"vote"=>"true", "post_id"=>"1"} | |
Post Load (0.3ms) SELECT "posts".* FROM "posts" WHERE "posts"."id" = ? LIMIT 1 [["id", "1"]] | |
(0.1ms) begin transaction | |
SQL (55.1ms) INSERT INTO "votes" ("created_at", "post_id", "updated_at", "vote") VALUES (?, ?, ?, ?) [["created_at", Fri, 19 Oct 2012 17:19:58 UTC +00:00], ["post_id", 1], ["updated_at", Fri, 19 Oct 2012 17:19:58 UTC +00:00], ["vote", 0]] | |
(2.5ms) commit transaction | |
(5.9ms) SELECT COUNT(*) FROM "votes" WHERE "votes"."post_id" = 1 AND "votes"."vote" = 0 | |
CACHE (0.0ms) SELECT COUNT(*) FROM "votes" WHERE "votes"."post_id" = 1 AND "votes"."vote" = 0 | |
Rendered votes/create.js.erb (31.9ms) | |
Completed 200 OK in 323ms (Views: 101.0ms | ActiveRecord: 67.5ms) | |
Started GET "/" for 127.0.0.1 at 2012-10-19 13:19:58 -0400 | |
Processing by PostsController#index as HTML | |
Post Load (0.2ms) SELECT "posts".* FROM "posts" | |
(0.1ms) SELECT COUNT(*) FROM "comments" WHERE "comments"."post_id" = 1 | |
(0.3ms) SELECT COUNT(*) FROM "votes" WHERE "votes"."post_id" = 1 AND "votes"."vote" = 0 | |
CACHE (0.0ms) SELECT COUNT(*) FROM "votes" WHERE "votes"."post_id" = 1 AND "votes"."vote" = 0 | |
Rendered posts/index.html.erb within layouts/application (76.2ms) | |
Completed 200 OK in 264ms (Views: 261.8ms | ActiveRecord: 1.1ms) | |
[2012-10-19 13:19:58] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true | |
Started GET "/assets/custom.css?body=1" for 127.0.0.1 at 2012-10-19 13:19:59 -0400 | |
Served asset /custom.css - 304 Not Modified (12ms) | |
[2012-10-19 13:19:59] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true | |
Started GET "/assets/application.css?body=1" for 127.0.0.1 at 2012-10-19 13:19:59 -0400 | |
Served asset /application.css - 304 Not Modified (13ms) | |
[2012-10-19 13:19:59] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true | |
Started GET "/assets/posts.css?body=1" for 127.0.0.1 at 2012-10-19 13:19:59 -0400 | |
Served asset /posts.css - 304 Not Modified (1ms) | |
[2012-10-19 13:19:59] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true | |
Started GET "/assets/jquery.js?body=1" for 127.0.0.1 at 2012-10-19 13:19:59 -0400 | |
Served asset /jquery.js - 304 Not Modified (4ms) | |
[2012-10-19 13:19:59] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true | |
Started GET "/assets/jquery_ujs.js?body=1" for 127.0.0.1 at 2012-10-19 13:19:59 -0400 | |
Served asset /jquery_ujs.js - 304 Not Modified (3ms) | |
[2012-10-19 13:19:59] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true | |
Started GET "/assets/posts.js?body=1" for 127.0.0.1 at 2012-10-19 13:19:59 -0400 | |
Served asset /posts.js - 304 Not Modified (2ms) | |
[2012-10-19 13:19:59] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true | |
Started GET "/assets/application.js?body=1" for 127.0.0.1 at 2012-10-19 13:19:59 -0400 | |
Served asset /application.js - 304 Not Modified (13ms) | |
[2012-10-19 13:19:59] WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment