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

ruby on rails 一步步开始(2)分页和简单查询

使用 will_paginate 进行分页和简单查询
在命令行下使用 gem install will_paginate 命令,出现下面结果安装成功
打开 books_controller.rb (你自己的控制器)
注释掉查找全部的方法,使用下面的方法,已经集成根据title进行查询
Ruby代码
#@books = Book.all   
@books = Book.paginate :page => params[:page],      
                               :per_page => 2,    
                               :conditions => ["title like ?", "%#{params[:search]}%"]    
    respond_to do |format|   
      format.html # index.html.erb   
      format.xml  { render :xml => @books }   
    end  
  end  
#@books = Book.all
@books = Book.paginate :page => params[:page],
:per_page => 2,
:conditions => ["title like ?", "%#{params[:search]}%"]
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @books }
end
end
 打开对应的 books_controller.rb 视图页面 index.html.erb
 添加查询功能
Html代码
<% form_tag books_path, :method => 'get' do %>    
<p>    
    <%= text_field_tag :search, params[:search] %>    
    <%= submit_ta


相关文档:

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 ......

Ruby和Python的语法比较


Ruby和Python的语法比较
 
 
 
其实Ruby和Python非常接近,比大多数别的语言要接近的多,所以喜欢用啥就用啥(大实话,虽然也是废话)。语法上的差别虽然有那么一点,大部分是syntax sugar,我斗胆稍微列几个(python我也忘得差不多了,不对的大家尽管来鞭尸吧),但是主要差异还是设计思想上的:灵活 ......

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的事项在这里就不多 ......

写的一个inter类模仿ruby整数的行为

我们知道ruby中对于整数的[],[]=,<<,>>操作是针对于二进制的值来运算的。
我现在写一个针对十进制数操作的类,拥有整数的所有方法,如下:
class InterEx
def initialize(val=0)
@val=val
end

def to_s
@val.to_s
end

def [](idx)
self.to_s[idx].to_i
end

d ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号