易截截图软件、单文件、免安装、纯绿色、仅160KB

Ruby实践—will_paginate实现分页

开发环境:
OS:Windows XP
Ruby:Ruby1.9.1
Rails:Rails2.3.5
will_paginate:will_paginate2.3.11
(在命令行中运行 gem install mislav-will_paginate --source http://gems.github.com )
IDE:Rubymine2.0.1
DB:mysql5.0.9
本例在上一个例子(Ruby实践—简单数据库操作)的基础上实现分页,利用的是will_paginate插件
一、安装will_paginate
(在命令行中运行 gem install mislav-will_paginate --source http://gems.github.com )
二、修改enviroment.rb
引用"will_paginate",在
   Rails::Initializer.run do |config|
   end
之后添加 require 'will_paginate' ,否则运行时报错“method not found 'paginate' ”
三、修改product_controller.rb
修改 index 方法为如下:
def index
# @products = Product.all
@products = Product.paginate :page => params[:page]||1, :per_page => 2
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @products }
end
end
#注:1是用户以http://localhost:3000/products 显示的第1页的数据;2是每页显示的记录数
@product_pages = Product.paginate :page => params[:page]||1, :per_page => 2
四、修改index.html.erb
添加如下引用
<%= will_paginate @products, :prev_label => 'pre', :next_label => 'next' %>
运行结果:
 


相关文档:

Ruby声音


转 Adding Sound to Your Ruby Apps
Have you ever thought about including sounds in your Ruby application? Used sparingly, sound may enhance your applications by adding audio cues or a custom touch. You could, for example, play a beep or chime that announces the completion of a lengthy process. Per ......

Windows平台的ruby IDE 点评

转自 http://www.javaeye.com/topic/57474 
Windows平台的ruby IDE 点评
在MacOS平台几乎没有什么争议性,大家都用TextMate。但是Windows平台可供选择和使用的IDE很多,却各有各的长处和短处。基于我用过的所有ruby IDE点评一下。windows平台的RoR IDE主要分为两类:一类是重量级的全功能IDE,例如Eclipse,Netbeans ......

Ruby on Rails 命令参考

1.1.Rails
1.1 创建一个Rails应用程序
$ rails app_name
可选项:
-d, database=xxx 指定安装一个数据库(mysql oracle postgresql sqlite2 sqlite3 ), 默认情况下是数据库
-r, ruby-path= 指定Ruby的安装路径,如果没有指定,scripts使用env去找Ruby
-f, freeze (冻结)freezes Rails在vendor/rails目录
1.2 API Docume ......

Ruby实践—连接Mysql

安装环境:
OS:Windows XP
Ruby: Ruby1.9.1
Mysql: Mysql5.1.46 (username/password: root/root  port:3306)
Ruby-Mysql Driver: mysql-2.8.1-x86-mswin32.gem
(注:用2.7.3版本的驱动在测试时会出现 require"mysql",找不到指定模块 错误)
IDE:RubyMine2.0.1
安装Ruby,RubyMine,Mysql的事项在这里就不多 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号