Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Rails:响应javascript_Ruby On Rails_Ajax_Ruby On Rails 3_Ruby On Rails 4 - Fatal编程技术网

Ruby on rails Rails:响应javascript

Ruby on rails Rails:响应javascript,ruby-on-rails,ajax,ruby-on-rails-3,ruby-on-rails-4,Ruby On Rails,Ajax,Ruby On Rails 3,Ruby On Rails 4,这是我的观点:(show.html.erb) 我想要的是在单击链接后更新show.html.erb的内容。(我正在使用ajax(remote=>true)。show.html.page应使用新值@total\u vote进行自我更新 如何执行此操作?添加vote_for.js.erb,然后将以下内容添加到文件中: $("body").prepend("<h1><%= @total_vote %></h1>") $(“正文”).prepend(“”) 但是我应

这是我的观点:
show.html.erb

我想要的是在单击链接后更新show.html.erb的内容。(我正在使用ajax(
remote=>true
)。show.html.page应使用新值
@total\u vote
进行自我更新


如何执行此操作?

添加vote_for.js.erb,然后将以下内容添加到文件中:

$("body").prepend("<h1><%= @total_vote %></h1>")
$(“正文”).prepend(“”)

但是我应该用选择器替换$(''body''),该选择器标识我要将文本放入的区域,对吗?是的,您可以这样做:
$('div#total(u vote').html('')
您还必须只保留format.js{}并删除format.html的行,或者将尝试加载vote_for.html视图。如果您想在禁用js的情况下捕获html,该怎么办?
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
$("body").prepend("<h1><%= @total_vote %></h1>")