如何做调查弹出窗口?,我有两个按钮“投票”、“查看”,查看可以用java script做,但是submit后就必须redirect_to(),我希望主页不做任何刷新之类的操作(比如,:action=>"index"),提交后在弹出窗口中查看投票情况,求高手帮忙,
用延时的办法了,submit时用Ajax发送更新数据库,无须返回HTML片断,延时弹出窗口,这样提交的数据就能反映在弹出窗口中了,不过我始终觉得这不是最好的办法!
main_controller.rb
class MainController < ApplicationController
def index
end
def indagate
@info=InfoCount.find(:first)
if params[:sub]=="提交"
case params[:item]
when "0"
@info.votes_best_add
when "1"
@info.votes_better_add
when "2"
@info.votes_good_add
end
end
end
def vote
@info=InfoCount.find(:first)
end
----------------------
info_count.rb
class InfoCount < ActiveRecord::Base
def votes_good_add#自加
self.class.increment_counter :votes_good, id
end
def votes_better_add#自加
self.class.increment_counter :votes_better, id
end
def votes_best_add#自加
self.class.increment_counter :votes_best, id
end
end
------------------
index.rhtml
<script language="javascript">
<!--
function popup() {
window.open('/main/vote','window','width=550,height=388,toolbar=no, status=no, menubar=no, resizable=no, scrollbars=yes');
}
function vote() {
setTimeout("popup()",1000);
}
-->
</script>
<%=javascript_include_tag "prototype"%>
<%=form_remote_tag(:url=>{:action=>:indagate})%>
<br>
<INPUT type=hidden value=1 name=id>
<INPUT type=radio value=0 name=item>好。<BR>
<INPUT type=radio value=1 name=item>一般。<BR>
<INPUT type=radio value=2 name=item>差。<BR><BR>
<input type="button" name="display" value="查看" onClick=popup()>
<input type="submit" name="sub" value="提交" onClick=vote()>
<%= end_form_tag %>