Ruby on Rails HTML表单语句大全(ZZ)

Ruby on Rails HTML表单语句大全


表单开始标签:
<%= form_tag { :action => :save }, { :method => :post } %>
Use :multipart => true to define a Mime-Multipart form (for file uploads)
表单结束标签:
<%= end_form_tag %>

文本框 Text fields
<%= text_field :modelname, :attribute_name, options  %>
生成:
<input type="text" name="modelname[attribute_name]" id="attributename" />

实例:

text_field "post", "title", "size" => 20
    <input  type="text" id="post_title" name="post[title]"
            size="20" value="#{@post.title}" />

隐藏框:
<%= hidden_field ... %>

密码框:
<%= password_field ... %>

文件框
<%= file_field ... %>

Rails Textarea框
<%= text_area ... %>
实例:
text_area "post", "body", "cols" => 20, "rows" => 40
    <textarea cols="20" rows="40" id="post_body" name="post[body]">
        #{@post.body}
    </textarea>

单选框 Radio Buttons
<%= radio_button :modelname, :attribute, :tag_value, options %>
实例:
radio_button "post", "category", "rails"
radio_button "post", "category", "java"
    <input type="radio" id="post_category" name="post[category]" value="rails"
           checked="checked" />
    <input type="radio" id="post_category" name="post[category]" value="java" />

多选框 Check Box
<%= check_box :modelname, :attribute, options, on_value, off_value %>
实例
check_box "post", "validated"   # post.validated? returns 1 or 0
    <input type="checkbox" id="post_validate" name="post[validated]"
           value="1" checked="checked" />
    <input name="post[validated]" type="hidden" value="0" />

check_box "puppy", "gooddog", {}, "yes", "no"
    <input type="checkbox" id="puppy_gooddog" name="puppy[gooddog]" value="yes" />
    <input name="puppy[gooddog]" type="hidden" value="no" />

<%= select :variable, :attribute, choices, options, html_options %>

下拉菜单框 Select Menu
select  "post",        
        "person_id",   
        Person.find_all.collect {|p| [ p.name, p.id ] },
        { :include_blank => true }

 <select name="post[person_id]">
   <option></option>
   <option value="1" selected="selected">David</option>
   <option value="2">Sam</option>
   <option value="3">Tobias</option>
 </select>

Collection Selection
<%= collection_select :variable, :attribute, choices, :id, :value %>

日期选择框:
<%= date_select :variable, :attribute, options %>
<%= datetime_select :variable, :attribute, options %>
实例:
date_select "post", "written_on"
date_select "user", "birthday", :start_year => 1910
date_select "user", "cc_date", :start_year => 2005,
                               :use_month_numbers => true,
                               :discard_day => true,
                               :order => [:year, :month]

datetime_select "post", "written_on"


引用自 http://www.cublog.cn/u/26076/showart_223824.html

posted on 2007-12-15 11:33 想飞就飞 阅读(3330) 评论(1)  编辑  收藏 所属分类: ROR

评论

# re: Ruby on Rails HTML表单语句大全(ZZ) 2009-03-11 11:26 fl1429

还行!  回复  更多评论   


只有注册用户登录后才能发表评论。


网站导航:
 

公告


导航

<2009年3月>
22232425262728
1234567
891011121314
15161718192021
22232425262728
2930311234

统计

常用链接

留言簿(13)

我参与的团队

随笔分类(69)

随笔档案(68)

最新随笔

搜索

积分与排名

最新评论

阅读排行榜

评论排行榜