Skip to content

Instantly share code, notes, and snippets.

@ddemaree
Created October 25, 2010 20:10
Show Gist options
  • Save ddemaree/645639 to your computer and use it in GitHub Desktop.
Save ddemaree/645639 to your computer and use it in GitHub Desktop.
Rails 3 ERb template showing a simple syntax for doing REST forms without unnecessary DOM class/ID cruft
<% form_tag @user = User.new do %>
<% fields_for @user do |user_form| %>
<div class="field">
<label>Name</label>
<%= user_form.text_field :name %>
</div>
<% end %>
<% end %>
<% form_tag @user = User.first, :method => :put do %>
<% fields_for @user do |user_form| %>
<div class="field">
<label>Name</label>
<%= user_form.text_field :name %>
</div>
<% end %>
<% end %>
<form accept-charset="UTF-8" action="/users" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /><input name="authenticity_token" type="hidden" value="wHmerRLGE0nrTsQZ6q02Qw/YvX9uwQvTWrrmYQ1rZQY=" /></div> <div class="field">
<label>Name</label>
<input id="user_name" name="user[name]" size="30" type="text" />
</div>
</form>
<form accept-charset="UTF-8" action="/users/1" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /><input name="_method" type="hidden" value="put" /><input name="authenticity_token" type="hidden" value="wHmerRLGE0nrTsQZ6q02Qw/YvX9uwQvTWrrmYQ1rZQY=" /></div> <div class="field">
<label>Name</label>
<input id="user_name" name="user[name]" size="30" type="text" value="David Demaree" />
</div>
</form>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment