=========================================================
VTC based Learning Note -- VIews
注意:
1,ruby區分大小寫!
2,可以編寫一些bat來保存常用命令如 ruby script/server
3,讓webrick使用其他端口的方法: ruby script/server -p 8000
=========================================================
1,helper
當你用ruby創建model或controller時,對應的helper.rb也被創建了。
2,form常用的helper函數
函數 | 作用 |
start_from_tag :action => 'create' submit_tag "create" end_form_tag |
創建form 提交到controller的create方法 |
text_field 'ObjName', 'ControlName' |
會創建一個對象, controller中可以用 params[:ObjName] 作爲類的new方法的參數 從而構造對象 |
password_field 'ObjName', 'ControlName' | 同上 |
hidden_field 'ObjName', 'ControlName' | 同上 |
datetime_select 'ObjName', 'ControlName' | 同上 |
text_area 'ObjName','ControlName' , {:cols =>'30', :rows => "10"} |
注意,還可以添加附加的設置, 如左邊的長寬 |
radio_button 'ObjName', 'ControlName' check_box 'ObjName', 'ControlName' file_field 'ObjName', 'ControlName' ....... |
生成radio button和check box 參考http://api.rubyonrails.com/的 ActionView::Helpers::FormHelper 等部分可以得到更多 |
3,實際上,還可能在網頁上出現不是屬於每個obj的UI元素,這些也有特定的函數來生成:
函數 | 作用 |
text_field_tag :sometext | not belong to a object, use params[:sometext] to access it |
password_field_tag | |
text_area_tag | 更多的參考http://api.rubyonrails.com/的FormTagHelper |