幾種常用Ruby表單語句總結概覽
作者:佚名
Ruby表單語句經常被我們用到,比如:表單開始標簽;表單結束標簽;文本框;隱藏框;密碼框;文件框;Rails Textarea框等等。
Ruby語言在實際使用中,通常都會遇到與HTML相關的操作。比如我們今天要為大家接介紹的Ruby表單語句的一些總結。希望對大家有用。#t#
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 %>
實例:
- 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" />
以上就是我們為大家總結的一些常用Ruby表單語句。
責任編輯:曹凱
來源:
博客園