Skip to content

Instantly share code, notes, and snippets.

@jferris
Created December 3, 2010 15:59
Show Gist options
  • Select an option

  • Save jferris/727136 to your computer and use it in GitHub Desktop.

Select an option

Save jferris/727136 to your computer and use it in GitHub Desktop.
semiformal
class UsersController < ApplicationController
def edit
assign_user_form
end
def update
if assign_user_form.commit
redirect_to @user, :flash => "User saved."
else
render 'new'
end
end
private
def assign_user_form
@user = User.find(params[:id])
@user_form = form_for(@user) do |form|
form.accept :email
form.accept :password
form.accept :password_confirmation
end
end
end
<!-- generate all fields/buttons -->
<%= render_form @user_form %>
<!-- choose fields -->
<%= render_form @user_form do |form| -%>
<%= form.fieldset do -%>
<!-- custom field -->
<%= form.field :email do |field| -%>
<%= field.label %>
<%= field.input %>
<a href="#" id="check_email">Check availability</a>
<% end -%>
<%= form.field :password -%>
<%= form.field :password_confirmation -%>
<% end -%>
<!-- default buttons -->
<%= form.buttons -%>
<!-- button with cancel -->
<%= form.buttons :cancel => user_path(@user) %>
<!-- custom buttons -->
<%= form.buttons do -%>
<%= form.commit_button 'Save User' %>
<% end -%>
<% end -%>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment