Ruby on Rails HTML表單語句大全(ZZ)

          Ruby on Rails HTML表單語句大全


          表單開始標簽:
          <%= 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  %>
          生成:
          <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}" />

          隱藏框:
          <%= 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>

          單選框 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" />

          多選框 Check Box
          <%= check_box :modelname, :attribute, options, on_value, off_value %>
          實例
          check_box "post", "validated"   # post.validated? returns 1 or 0
              <input type="checkbox" id="post_validate" name="post[validated]"
                     value="1" checked="checked" />
              <input name="post[validated]" type="hidden" value="0" />

          check_box "puppy", "gooddog", {}, "yes", "no"
              <input type="checkbox" id="puppy_gooddog" name="puppy[gooddog]" value="yes" />
              <input name="puppy[gooddog]" type="hidden" 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 }

           <select name="post[person_id]">
             <option></option>
             <option value="1" selected="selected">David</option>
             <option value="2">Sam</option>
             <option value="3">Tobias</option>
           </select>

          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"


          引用自 http://www.cublog.cn/u/26076/showart_223824.html

          posted on 2007-12-15 11:33 想飛就飛 閱讀(3343) 評論(1)  編輯  收藏 所屬分類: ROR

          評論

          # re: Ruby on Rails HTML表單語句大全(ZZ) 2009-03-11 11:26 fl1429

          還行!  回復  更多評論   

          公告


          導航

          <2007年12月>
          2526272829301
          2345678
          9101112131415
          16171819202122
          23242526272829
          303112345

          統計

          常用鏈接

          留言簿(13)

          我參與的團隊

          隨筆分類(69)

          隨筆檔案(68)

          最新隨筆

          搜索

          積分與排名

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 嘉义县| 鹤岗市| 宜黄县| 紫金县| 成安县| 陆良县| 新巴尔虎右旗| 房产| 吉木萨尔县| 桓台县| 公安县| 平度市| 舒城县| 印江| 马尔康县| 济南市| 保定市| 内江市| 峨边| 中牟县| 岳普湖县| 綦江县| 鄂尔多斯市| 崇州市| 葫芦岛市| 中山市| 锡林浩特市| 黑山县| 鹤山市| 格尔木市| 祁门县| 浦城县| 通江县| 冷水江市| 库尔勒市| 蒙自县| 东兰县| 黄山市| 视频| 榕江县| 渝北区|