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

Ruby form的两种写法

下面介绍Ruby form的两种写法。
Ruby form写法一:使用form_for
< % form_for :order, :url => { :action => :save_order } do |form| %>   < p>    < %= label :order, :name, "Name:" %>    < %= form.text_field :name, :size => 40 %>     < /p>   < p>    < %= label :order, :address, "Address:" %>    < %= form.text_area :address, :rows => 3, :cols => 40 %>   < /p>   < p>    < %= label :order, :email, "E-Mail:" %>    < %= form.text_field :email, :size => 40 %>   < /p>   < %= submit_tag "Place Order" , :class => "submit" %> < % end %> 
来看看解释
引用
There are two interesting things in this code. First, the form_for helper on line 1 sets up a standard HTML form. But it does more. The first parameter, : order,tells the method that it’s dealing with an object in an instance variable named @order. The helper uses this information when naming fields and when arranging for the field values to be passed back to the controller.
The :url parameter tells the helper what to do when the user hits the submit button. In this case, we’ll generate an HTTP POST request that’ll end up getting handled by the save_order action in the controller.
而每个form的helper方法,如form.text_area,form_text_field,后面跟的符号,如:name,:address,:email,等都是这个model的属性。form_f


相关文档:

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类变量在development模式失效

分页中用到类变量,主要是用来标记“页码输入框”的id 如果一个页面有几个分页,“页码输入框”的id要是不同的才能分清是哪个要分页。使用类变量就是为了达到这个目的,让所有的对象实例共用一个变量,不必每次重新初始化变量。 类变量使用代码示例 1 require 'ruby-debug'
2 debugger
3 cla ......

ruby调用平台指令删除指定文件夹

正常情况下,ruby如果发现文件夹中有system,readonly,hide类型的文件,则是不能直接删除
他们的。如何解决呢?
以其人之道还治其人之身!
def dryf(fpath) #destroy file
x = Iconv.iconv('utf-8','gbk',fpath).to_s
%x{attrib -R -S -H \"#{Iconv.iconv('gbk','utf-8',x).to_s}\"}
f = File.new(f ......

Ruby实践—HelloWorld

开发环境
OS:WindowsXP
Ruby: Ruby1.9.1
Rails: Rails2.3.5
IDE: RubyMine2.0.1
1、创建Rails工程
2、修改 /config/database.yml
自动创建的工程中默认数据库连接的是sqlite,如果没有安装此数据库,需要修改该配置(本例中使用的是mysql)
# Mysql Version 5.1.46
development:
adapter: mysql
database: ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号