[英]Rails :respond_to javascript
This is my view: ( show.html.erb
) 这是我的观点: (
show.html.erb
)
<%=link_to vote_for, vote_for_question_path(@question), :remote => true%>
This is the action that the link calls in the question_controller
: 这是链接在
question_controller
调用的操作:
def vote_for
@quest_vote_for = Question.find(params[:id])
current_user.vote_exclusively_for(@quest_vote_for)
@total_vote = current_user.total_votes
respond_to do |format|
format.js{}
format.html
end
end
What I want, is to update the content of the show.html.erb after the link is clicked. 我想要的是单击链接后更新show.html.erb的内容。 (I am using ajax (
remote=>true
)). (我正在使用ajax(
remote=>true
))。 The show.html.page should update itself with the new value of @total_vote
. show.html.page应该使用@total_vote的新值进行
@total_vote
。
How can I do this? 我怎样才能做到这一点?
添加vote_for.js.erb,然后将以下内容添加到您的文件中:
$("body").prepend("<h1><%= @total_vote %></h1>")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.