r3 - 14 May 2006 - 01:07:46 - JaruTangpoonpholwiwatYou are here: SETEC Wiki >  Knowledge Web  > WebTechnologyCategory > RubyOnRails > FieldHelpersOnRails
-- JaruTangpoonpholwiwat - 22 May 2012 - 13:57

Field Helpers

Text Field

text_field(:variable, :attribute, options)
hidden_field(:variable, :attribute, options)
password_field(:variable, :attribute, options)

เป็น tag ของการ input โดยแบ่งเป็นประเภทได้แก่ text, hidden, password
โดยทั่วไปในโครงสร้างของการเขียน syntax ของ rails เพื่ออ้างอิงใช้งาน object นั้นสามารถเขียนได้ดังนี้

@variable.attribute

Options ทั่วไปของ Text Fields

:size => “xx”
:maxsize => “xx”

Text Area

text_area(:variable, :attribute, options)

Options ทั่วไปของ Text Areas

:rows => “xx”
:cols => “xx”

Radio Buttons

Checkboxes

check_box(:variable, :attribute, options, on_value, : off_value)

การสร้าง checkbox ถูก checked จะทำให้ attribute จะมีค่าเป็น true
โดย Default ค่าของ attribute มีเป็น 1 ในกรณีที่ checkbox ถูก checked นอกนั้น attribute จะมีค่าเป็น 0

Selection Lists

Date and Time Fields

date_select(:variable, :attribute, options)
datetime_select(:variable, :attribute, options)
select_date(date = Date.today, options)
select_day(date, options)
select_month(date, options)
select_year(date, options)

select_datetime(date = Time.now, options)
select_hour(time, options)
select_minute(time, options)
select_second(time, options)
select_time(time, options)

options
Time.now แสดง เวลาปัจจุบัน
:field_name => "time_end_minute" ตั้งชื่อ attribute name ชื่อ "time_end_minute"
:minute_step => 30 แสดงเวลาครั้งละ 30 นาที มี options สามารถเลือกได้คือ 0, 15, 30, 45
:add_month_numbers => ture แสดง เดือนเป็นวตัวเลข
:use_month_numbers => ture
:discard_month => true ตัดฟังก์ชัน month ออกจาก object
:discard_day => true ตัดฟังก์ชัน day ออกจาก object
:discard_hour => true ตัดฟังก์ชัน hour ออกจาก object
:discard_minute => true ตัดฟังก์ชัน minute ออกจาก object
:discard_second => true ตัดฟังก์ชัน second ออกจาก object
:order => [:day, : month, :year] เรียง object ตามที่กำหนด

โดย default จะแสดง year ก่อนและหลัง 5 ปี ถ้าจะกำหนดปีเอง สามารถกำหนด
:start_year => yyyy กำหนดปีเริ่มต้น
:end_year => yyyy กำหนดปีสิ้นสุด

สามารถ เขียนได้ 2 แบบ

1. date_select("reservation", "date_reserved")
2. date_select(:reservation, :date_reserved)
Edit | Attach | Printable | Raw View | Backlinks: Web, All Webs | History: r3 < r2 < r1 | More topic actions
 
Powered by SETEC Wiki
Copyright ©2012 by National Electronics and Computer Technology Center, NECTEC.
Ideas, requests, problems regarding SETEC Wiki? Send feedback