Last active
November 3, 2015 10:59
-
-
Save wagurano/bcd5c33850c52f352577 to your computer and use it in GitHub Desktop.
form-example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h1>Test</h1> | |
<%= form_tag { 'basic form tag' } %> | |
<%= form_tag('/posts') { 'form posts'} %> | |
<%= form_tag('/posts/1', method: :put) { 'form posts/1'} %> | |
<%= form_tag('/upload', multipart: true) { 'form upload' } %> | |
<%= form_tag('/posts') do -%> | |
<div><%= submit_tag 'Save' %></div> | |
<% end -%> | |
<%= form_tag('/posts', remote: true) { 'remote' } %> | |
<%= form_tag('http://far.away.com/form', authenticity_token: false) { 'token false' } %> | |
<%= form_tag('http://far.away.com/form', authenticity_token: "cf50faa3fe97702ca1ae") { 'token used' } %> | |
<%= form_tag('/posts', style: "font-size:50px" ) { 'html attributes' } %> | |
<%= form_tag("/search", method: "get") do %> | |
<%= label_tag(:q, "Search for:") %> | |
<%= text_field_tag(:q) %> | |
<%= submit_tag("Search") %> | |
<% end %> | |
<%= form_tag(controller: "people", action: "search", method: "get", class: "nifty_form") { 'not used to hash bracket' } %> | |
<%= form_tag({controller: "people", action: "search"}, method: "get", class: "nifty_form") { 'hash bracket' } %> | |
<%= form_tag do %> | |
<%= check_box_tag(:pet_dog) %> | |
<%= label_tag(:pet_dog, "I own a dog") %> | |
<%= check_box_tag(:pet_cat) %> | |
<%= label_tag(:pet_cat, "I own a cat") %> | |
<%= radio_button_tag(:age, "child") %> | |
<%= label_tag(:age_child, "I am younger than 21") %> | |
<%= radio_button_tag(:age, "adult") %> | |
<%= label_tag(:age_adult, "I'm over 21") %> | |
<% end %> | |
<%= form_tag do %> | |
<%= radio_button_tag(:age, "child") %> | |
<%= label_tag(:age_child, "I am younger than 21") %> | |
<%= radio_button_tag(:age, "adult") %> | |
<%= label_tag(:age_adult, "I'm over 21") %> | |
<% end %> | |
<%= form_tag do %> | |
<%= label_tag(:message, "message:") %> | |
<br/> | |
<%= text_area_tag(:message, "Hi, nice site", size: "24x6") %> | |
<br/> | |
<%= label_tag(:password, "password:") %> | |
<br/> | |
<%= password_field_tag(:password) %> | |
<br/> | |
<%= label_tag(:parent_id, "hidden:") %> | |
<br/> | |
<%= hidden_field_tag(:parent_id, "5") %> | |
<br/> | |
<%= label_tag(:user, "user search:") %> | |
<br/> | |
<%= search_field(:user, :name) %> | |
<br/> | |
<%= label_tag(:user, "user telephone:") %> | |
<br/> | |
<%= telephone_field(:user, :phone) %> | |
<br/> | |
<%= label_tag(:born_on, "user birthday:") %> | |
<br/> | |
<%= date_field(:user, :born_on) %> | |
<br/> | |
<%= label_tag(:meeting_time, "user meeting_time:") %> | |
<br/> | |
<%= datetime_field(:user, :meeting_time) %> | |
<br/> | |
<%= label_tag(:graduation_day, "user graduation_day:") %> | |
<br/> | |
<%= datetime_local_field(:user, :graduation_day) %> | |
<br/> | |
<%= label_tag(:birthday_month, "user birthday_month:") %> | |
<br/> | |
<%= month_field(:user, :birthday_month) %> | |
<br/> | |
<%= label_tag(:birthday_week, "user birthday_week:") %> | |
<br/> | |
<%= week_field(:user, :birthday_week) %> | |
<br/> | |
<%= label_tag(:homepage, "user homepage:") %> | |
<br/> | |
<%= url_field(:user, :homepage) %> | |
<br/> | |
<%= label_tag(:address, "user address:") %> | |
<br/> | |
<%= email_field(:user, :address) %> | |
<br/> | |
<%= label_tag(:favorite_color, "user favorite_color:") %> | |
<br/> | |
<%= color_field(:user, :favorite_color) %> | |
<br/> | |
<%= label_tag(:started_at, "task started_at:") %> | |
<br/> | |
<%= time_field(:task, :started_at) %> | |
<br/> | |
<%= label_tag(:price, "product price:") %> | |
<br/> | |
<%= number_field(:product, :price, in: 1.0..20.0, step: 0.5) %> | |
<br/> | |
<%= label_tag(:discount, "product discount:") %> | |
<br/> | |
<%= range_field(:product, :discount, in: 1..100) %> | |
<% end %> | |
<%= text_field(:person, :name) %> | |
<%= form_for :person do |f| %> | |
First name: <%= f.text_field :first_name %><br /> | |
Last name : <%= f.text_field :last_name %><br /> | |
Biography : <%= f.text_area :biography %><br /> | |
Admin? : <%= f.check_box :admin %><br /> | |
<%= f.submit %> | |
<% end %> | |
<% @article = Article.new %> | |
<%= form_for @article do |f| %> | |
instance value | |
<% end %> | |
<%= form_for(@article, as: :client) do |f| %> | |
as option | |
<% end %> | |
<% test_article = Article.new %> | |
<%= form_for test_article do |f| %> | |
local variable | |
<% end %> | |
<% @person = Person.new %> | |
<% @person.build_contact %> | |
<%= form_for @person, url: { controller: "person", action: "create" } do |person_form| %> | |
<%= person_form.text_field :name %> | |
<%= fields_for @person.contact do |contact_form| %> | |
<%= contact_form.text_field :telephone %> | |
<% end %> | |
<%= person_form.submit %> | |
<% end %> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment