• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Ruby on Rails HTML表单语句大全

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

转自:http://www.cslog.cn/Content/ruby_on_rails_html_form

表单开始标签:
<%= 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]" />

实例:

text_field "post", "title", "size" => 20
    <input  type="text"  
            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" >
        #{@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"  
           checked="checked" />
    <input type="radio" />

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

check_box "puppy", "gooddog", {}, "yes", "no"
    <input type="checkbox" />
    <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"

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Ruby初探发布时间:2022-07-13
下一篇:
Ruby:PrintWIN32OLEmethodnamesinRuby发布时间:2022-07-13
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap