ページをリロードせずに、Rails モデルのデータを更新する必要があります (AJAX)。
http://railscasts.com/episodes/364-active-record-reputation-system?autoplay=trueのような評判システムがあります
私のコントローラーには、次のメソッドがあります。
def vote
value = params[:type] == "up" ? 1 : -1
@idea = Idea.find(params[:id])
@idea.add_or_update_evaluation(:votes, value, current_user)
redirect_to :back, notice: "Thank you for voting!"
end
私の見解では、これがあります:
<% if current_user && !current_user.voted_for?(idea) %>
| <%= link_to "LoV", vote_idea_path(idea, type: "up"), method: "post" %>
<% end %>
ページをリロードせずに次のデータを更新したいと思います。私のアプリケーション レイアウト ファイルには次のようなものがあります。
strong>(<%= current_user.reputation_value_for(:votes).to_i %>).</strong>
<strong>LoV's(<%= link_to current_user.evaluations.count, user_path(current_user)%>)</strong>
そのメソッド「投票」をAJAXでレンダリングするにはどうすればよいですか?
どうもありがとう。