0 0

ajax on rails实现页面局部刷新15

[color=darkblue][/color]最近在做项目时遇到问题、我的环境是rails3.0.7,ruby1.9.2,mysql6.0.  想要实现的功能是提交表单后,实现局部刷新,只刷新要显示的那个模块。具体如下:


在views/fdinesearch/fdinesearch.html.erb 文件中

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="../../../javascripts/prototype.js" type="text/javascript"></script>
<%= javascript_include_tag :defaults %>
</head>
<body>
     
<div class="right" style="width:79%">
   <div id="dineselect" style="padding-left:20px">
      <%form_tag 'fdinesearch', :remote => true do%>
   <select name="year" id="select1">
    <option><%=@thisyear%></option>
    <option><%=@agoyear%></option>
    <option><%=@nextyear%></option>
   </select>
   <label for="select1">年</label>
   <select name="month" id="select2">
    <option value='6'>6</option>
    <option value='7'>7</option>

      </select>
   <label for="select2">月</label>

   <%= submit_tag '查看', :name => 'look'%> 
  
   <%end%>
</div>
   <br>
     
<div id="rightmain">
       <%=render :partial =>"fdinesearch/tablesearch",:collection  => @sadines%>
</div>
  </div>
</body>
</html>

在views/fdinesearch/tablesearch文件中
<table id="customers" width="80%">
  <tr>
  <th width="10%">aa</th>
<th width="10%">qq</th>

</tr>      
<%@sadines.each do |sd|%>
<tr>
<td><%=sd.id%></td>
<td><%=sd.peopleid%></td>
</tr>
<%end%>
</table>

在controllers/fdinesearch 文件中
class FdinesearchController < ApplicationController
def fdinesearch
t = Time.new
time = t.to_a
@thisyear = time[5]
@agoyear = (time[5].to_i - 1).to_s
@nextyear = (time[5].to_i + 1).to_s
year = params[:year]
month = params[:month]
yearmonth = year.to_s + "/" + month.to_s

if params[:look]
@sadines = DineAllowance.find(:all,:conditions  => ["da_ym = ? ",yearmonth])
end
end
end

实现的功能是选择年和月,然后搜索,将搜索的结果显示在下面的rightmain  div中  controller上面的时间计算是为了在view中动态生成年月
 

2012年7月24日 09:01
目前还没有答案

相关推荐

    Ajax on Rails (PPT)

    Ajax on Rails 的 PPT。 pdf格式。

    Ajax on Rails

    Learn to build dynamic, interactive web applications using the two most important approaches to web development today: Ajax and the phenomenally efficient Ruby on Rails platform. This book teaches ...

    ajax on rails

    ajax on rails压缩包,全英文

    跨越边界 Ajax on Rails

    跨越边界 Ajax on Rails(英文版)

    跨越边界1:Ajax on Rails

    您一定知道Ajax是这样一种编程技术,它...Ruby on Rails框架和Ajax的完美集成所产生的力量在一定程度上促成了该框架的繁荣。本文全面介绍了两个简单的Ajax例子,延着这个思路介绍了Ruby/Ajax这一组合如此成功的原因。

    Ruby on Rails Guides v2 - Ruby on Rails 4.2.5

    Ruby on Rails Guides v2 - Ruby on Rails 4.2.5

    Ruby on Rails Tutorial

    《Ruby on Rails Tutorial》中文版(原书第2版,涵盖 Rails 4) Ruby 是一门很美的计算机语言,其设计原则就是“让编程人员快乐”。David Heinemeier Hansson 就是看重了这一点,才在开发 Rails 框架时选择了 Ruby...

    Ruby On Rails中文教材(PDF)

    Ruby On Rails中文教材(PDF)

    《Ruby on Rails Web开发学习实录》

    全书共分17章,主要内容包括:搭建ruby on rails开发平台、ruby语言的基础知识(像控制语句、面向对象、数组和块等)、文件处理、数据库持久化、rails控制器和路由、视图模板以及发送邮件和ajax等。 《ruby on rails ...

    ruby on rails社区网站开发源码

    ruby on rails社区网站开发源码

    免费Ubuntu系统ruby on rails安装【保姆级教程】

    Ubuntu系统ruby on rails安装 Ubuntu系统ruby on rails安装 Ubuntu系统ruby on rails安装 Ubuntu系统ruby on rails安装 Ubuntu系统ruby on rails安装 Ubuntu系统ruby on rails安装 Ubuntu系统ruby on rails安装 ...

    ruby on rails对mongodb的操作

    ruby on rails对mongodb的操作ruby on rails对mongodb的操作ruby on rails对mongodb的操作ruby on rails对mongodb的操作

    Ruby on Rails中文指南

    Ruby on Rails中文指南

    提升Ruby on Rails性能的几个解决方案

    Ruby On Rails 框架自它提出之日起就受到广泛关注,在“不要重复自己”,“约定优于配置”等思想的指导下,Rails 带给 Web 开发者的是极高的开发效率。 ActiveRecord 的灵活让你再也不用配置繁琐的 Hibernate 即可...

    Ruby On Rails教程

    Ruby On Rails 官方教程,这本书讲解如何使用 Ruby on Rails 框架开发应用,以及如何把应用部署到生成环境。本书使用 Rails 默认的开发工具栈开发了一个完整的社交应用(类似 Twitter)。读完本书后你将掌握如何使用...

    ruby on rails最新版

    ruby on rails最新版 这是本人精心收集的重要软件

Global site tag (gtag.js) - Google Analytics