我需要更新我的軌道模型的一些數據,而無需重新加載頁面(AJAX)。呼叫helper方法的Rails
我有一個信譽系統,如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?
非常感謝。
您好,感謝您的回答,但我沒有votes_controller,投票方法是我的想法控制器裏面,所以我怎麼能處理好與一個Ajax請求的方法? –
這個答案並沒有真正地建立任何東西......當問題清楚地指向rails輔助方法時,你指的是你的答案中的一個控制器。 – cereallarceny
@cereallarceny你的答案在哪裏? – bricker