Skip to content

Instantly share code, notes, and snippets.

@kejyun
Last active December 17, 2015 17:39
Show Gist options
  • Save kejyun/5648002 to your computer and use it in GitHub Desktop.
Save kejyun/5648002 to your computer and use it in GitHub Desktop.
Rails Helper Form For
<!-- 程式:沒有參數-->
<%= form_tag do %>
表單資料
<% end %>
<!-- 輸出 -->
<form accept-charset="UTF-8" action="/" method="post">
<div style="margin:0;padding:0;display:inline">
<input name="utf8" type="hidden" value="&#x2713;" />
<input name="authenticity_token" type="hidden" value="s1h4sM75vOxLx25I7R9Y0jXlpV+8LsA5Kpp+l2GcLkg="
/>
</div>
表單資料
</form>
<!------------------ 強大的分隔線 ------------------>
<!-- 程式:加入action及method -->
<%= form_tag("/search", :method => "get") do %>
表單資料
<% end %>
<!-- 輸出 -->
<form accept-charset="UTF-8" action="/search" method="get">
<div style="margin:0;padding:0;display:inline">
<input name="utf8" type="hidden" value="&#x2713;" />
</div>
表單資料
</form>
<!------------------ 強大的分隔線 ------------------>
<!-- 程式:加入欄位 -->
<%= form_tag("/search", :method => "get") do %>
<%= label_tag(:q, "Search for:") %>
<%= text_field_tag(:q) %>
<%= submit_tag("Search") %>
<% end %>
<!-- 輸出 -->
<form accept-charset="UTF-8" action="/search" method="get"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /></div>
<label for="q">Search for:</label>
<input id="q" name="q" type="text" />
<input name="commit" type="submit" value="Search" />
</form>
<!------------------ 強大的分隔線 ------------------>
<!-- 程式:多參數controller,action,method,class -->
<%=form_tag( :controller=> "user",
:action => "new",
:method => "get",
:class => "nifty_form")
do %>
<% end %>
<!-- 輸出 -->
<form accept-charset="UTF-8" action="/user/new?class=nifty_form&amp;method=get"
method="post">
<div style="margin:0;padding:0;display:inline">
<input name="utf8" type="hidden" value="&#x2713;" />
<input name="authenticity_token" type="hidden" value="s1h4sM75vOxLx25I7R9Y0jXlpV+8LsA5Kpp+l2GcLkg=" />
</div>
</form>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment