Ruby语言在实际使用中,通常都会遇到与HTML相关的操作。比如我们今天要为大家接介绍的Ruby表单语句的一些总结。希望对大家有用。
Ruby表单语句之表单开始标签:
- < %= form_tag { :action => :save },
{ :method => :post } %> - Use :multipart => true to
define a Mime-Multipart
form (for file uploads)
表单结束标签:
- < %= end_form_tag %>
Ruby表单语句之文本框 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}"
/> Ruby表单语句之隐藏框:
< %= 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> Ruby表单语句之单选框 Radio Buttons
< %= radio_button :modelname, :attribute, :tag_value, options %>
实例: