Ruby 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,
- rder => [:year, :month]
- datetime_select "post", "written_on"
复制代码http://hi.baidu.com/zhangfeiadts/blog/item/b5437489c3913fb00e244435.html
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
谢谢艹艹。
谢啥啊,太见外了,呵呵,服务大家嘛!
回复 3# 中关村村草
好村艹!