ITPub博客

首页 > 应用开发 > IT综合 > Ruby on Rails HTML表单语句大全[Z]

Ruby on Rails HTML表单语句大全[Z]

原创 IT综合 作者:CharlesCui 时间:2008-03-24 14:20:25 0 删除 编辑

表单开始标签:
<%= 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 %>
生成:

实例:

text_field "post", "title", "size" => 20
size="20" value="#{@post.title}" />

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

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

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

Rails Textarea框
<%= text_area ... %>
实例:
text_area "post", "body", "cols" => 20, "rows" => 40

单选框 Radio Buttons<%= radio_button :modelname, :attribute, :tag_value, options %>
实例:
radio_button "post", "category", "rails"
radio_button "post", "category", "java"
value="rails"
checked="checked" />
value="java" />

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

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

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"

[@more@]

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/9934490/viewspace-1001387/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
  • 博文量
    52
  • 访问量
    265800