Skip to content

Instantly share code, notes, and snippets.

@ykyk1218
Last active August 29, 2015 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ykyk1218/00dbf24d1f9861febace to your computer and use it in GitHub Desktop.
Save ykyk1218/00dbf24d1f9861febace to your computer and use it in GitHub Desktop.
Railsのフォーム基本的な作成方法まとめ(form_forとかform_tag) ref: http://qiita.com/ykyk1218/items/2541a313aac0f0e5d81a
<% form_for(@article) do |f| %>
<div><%= f.text_field :title, class: "hogehoge" %></div>
<%= f.submit %>
<% end %>
<% form_for(@article) do |f| %>
<div><%= f.text_field :title, class: "hogehoge" %></div>
<%= f.submit %>
<% end %>
<% form_for([:admin, @article]) do |f| %>
<% end %>
<% form_for([:admin, @article]) do |f| %>
<% end %>
<% form_tag(:controller => article, :action => create) %>
<div><%= text_field :title, class: "hogehoge" %></div>
<%= submit_tag "作成" %>
<% end %>
<% form_tag(:controller => article, :action => create) %>
<div><%= text_field :title, class: "hogehoge" %></div>
<%= submit_tag "作成" %>
<% end %>
<%= f.text_field :title, class: "hogehoge" %>
<%= f.text_field :title, class: "hogehoge" %>
<%= f.text_area :content, class: "hogehoge", size: "100x50" %>
<%= f.text_area :content, class: "hogehoge", size: "100x50" %>
<%= f.collection_select :category, Category.all, :id, :category_name, include_blank: true %>
<%= f.collection_select :category, Category.all, :id, :category_name, include_blank: true %>
<%= f.collection_check_boxes(:article, :tag_ids, Tag.all, :id, :tag_name) do |b| %>
<%= b.label {b.check_box + b.text} %>
<% end %>
<%= f.collection_check_boxes(:article, :tag_ids, Tag.all, :id, :tag_name) do |b| %>
<%= b.label {b.check_box + b.text} %>
<% end %>
params.require(:article).permit({:tag_ids=>[]}
<%= f.collection_radio_buttons(:article, :type_ids, Type.all, :id, :type_name) do |b| %>
<%= b.label {b.radio_button + b.text} %>
<% end %>
<%= f.collection_radio_buttons(:article, :type_ids, Type.all, :id, :type_name) do |b| %>
<%= b.label {b.radio_button + b.text} %>
<% end %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment