{"id":7033,"date":"2014-05-17T00:23:31","date_gmt":"2014-05-17T00:23:31","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/05\/17\/rails-makevoteable-help-creating-user-voting-link-and-custom-error-message-collection-of-common-programming-errors\/"},"modified":"2014-05-17T00:23:31","modified_gmt":"2014-05-17T00:23:31","slug":"rails-makevoteable-help-creating-user-voting-link-and-custom-error-message-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/05\/17\/rails-makevoteable-help-creating-user-voting-link-and-custom-error-message-collection-of-common-programming-errors\/","title":{"rendered":"Rails makevoteable help creating user voting link and custom error message-Collection of common programming errors"},"content":{"rendered":"<p>I am having that problem with the gem makevoteable that when the page is loaded the post gets upvoted automatic. Instead of just having a link the user can click and upvote. When the page is reloaded I get the AlreadyVotedError in view. I would prefer a more user friendly error message as &#8220;You already voted this post&#8221;<\/p>\n<p>My view:<\/p>\n<pre><code>\n  <\/code><\/pre>\n<pre>\n  <br \/>\n  <br \/>\n \n<\/pre>\n<p><code>UPDATE:<\/code><\/p>\n<p><code>My route.rb: <code>match 'stem_op\/:id' =&gt; 'posts#vote_up', :as =&gt; 'stem_op'<\/code><\/code><\/p>\n<p>My public controller:<\/p>\n<pre><code>def vote_up\n  @post = Post.find(params[:id])\n  current_user.up_vote(@post)\n  flash[:message] = 'Thanks for voting!'\n  redirect_to post_path(@post)\nrescue MakeVoteable::Exceptions::AlreadyVotedError\n  flash[:error] = 'Already voted!'\n  redirect_to post_path(@post)\nend\n<\/code><\/pre>\n<p>My view:<\/p>\n<pre><code>\n  <\/code><\/pre>\n<pre>\n  <br \/>\n  <br \/> \n  \n\n<\/pre>\n<p><code>When I try to vote_up a post I get this error:<\/code><\/p>\n<p><code>Template missing - Do I really need a blank view file?<\/code><\/p>\n<p><code>UPDATE:<\/code><\/p>\n<pre><code><code>def vote_up\n  @post = Post.find(params[:id])\n  current_user.up_vote(@post)\n  flash[:message] = 'Thanks for voting!'\n  redirect_to post_path(@post)\nrescue MakeVoteable::Exceptions::AlreadyVotedError\n  flash[:error] = 'Already voted!'\n  redirect_to post_path(@post)\nend\n<\/code><\/code><\/pre>\n<p>Error:<\/p>\n<pre><code>SyntaxError in PostsController#vote_up\n\nC:\/Rails\/den\/app\/controllers\/posts_controller.rb:103: syntax error, unexpected keyword_end, expecting $end\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I am having that problem with the gem makevoteable that when the page is loaded the post gets upvoted automatic. Instead of just having a link the user can click and upvote. When the page is reloaded I get the AlreadyVotedError in view. I would prefer a more user friendly error message as &#8220;You already [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-7033","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/7033","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=7033"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/7033\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=7033"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=7033"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=7033"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}