Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A clarification of "<code>vote_for</code> belongs in your controller":</p> <p>You have:</p> <pre><code>&lt;%= link_to "Vote Up", current_user.vote_for(answer) %&gt; </code></pre> <p>What you really want is:</p> <pre><code>&lt;%= link_to "Vote Up", :controller =&gt; 'my_controller', :action =&gt; 'vote', :id =&gt; answer %&gt; </code></pre> <p>The <code>current_user.vote_for</code> method is a method on the server. If you call that method in your view (.rhtml file), the vote will happen when the page is rendered, not when the user clicks the link. Instead, create a 'vote' method on an appropriate controller (I called it <code>my_controller</code> here, make it whatever you want). The <code>vote</code> method then looks like the vote_fu example. The link_to creates a hyperlink to the voting action.</p> <p>If you're trying to do this via ajax, replace <code>link_to</code> with <code>link_to_remote</code>.</p> <pre><code>&lt;%= link_to_remote "Vote Up", :url =&gt; { :controller =&gt; 'my_controller', :action =&gt; 'vote', :id =&gt; answer } %&gt; </code></pre> <p>If your views/my_controller/vote template file is '.rjs', the javascript in that file will be executed when the result of the method returns to the page. If it is '.rhtml', you should look into the helpers for <code>link_to_remote</code> for easily updating a div on the page with the contains of the result of the method (<a href="http://api.rubyonrails.org/classes/ActionView/Helpers/PrototypeHelper.html#M001645" rel="nofollow noreferrer">http://api.rubyonrails.org/classes/ActionView/Helpers/PrototypeHelper.html#M001645</a> - you want the <code>:update</code> option )</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload