Skip to content

Instantly share code, notes, and snippets.

@esparkman
Created June 30, 2010 04:33
Show Gist options
  • Save esparkman/458241 to your computer and use it in GitHub Desktop.
Save esparkman/458241 to your computer and use it in GitHub Desktop.
From Devise views
<h2>Edit <%= resource_name.to_s.humanize %></h2>
<% form_for resource_name, resource, :url => registration_path(resource_name), :html => { :method => :put } do |f| -%>
<%= f.error_messages %>
<p><%= f.label :email %></p>
<p><%= f.text_field :email %></p>
<p><%= f.label :password %> <i>(leave blank if you don't want to change it)</i></p>
<p><%= f.password_field :password %></p>
<p><%= f.label :password_confirmation %></p>
<p><%= f.password_field :password_confirmation %></p>
<p><%= f.label :current_password %> <i>(we need your current password to confirm your changes)</i></p>
<p><%= f.password_field :current_password %></p>
<% f.fields_for :profile do |profile| %>
<p>
<%= profile.label :name %><br />
<%= profile.text_field :name %>
</p>
<p>
<%= profile.label :url %><br />
<%= profile.text_field :url %>
</p>
<p>
<%= profile.label :company %><br />
<%= profile.text_field :company %>
</p>
<p>
<%= profile.label :location %><br />
<%= profile.text_field :location %>
</p>
<% end %>
<p><%= f.submit "Update" %></p>
<% end -%>
<h3>Cancel my account</h3>
<p>Unhappy? <%= link_to "Cancel my account", registration_path(resource_name), :confirm => "Are you sure?", :method => :delete %>.</p>
<%= render :partial => "shared/devise_links" %>
Profile had user_id for has one and belongs to association.
class Profile < ActiveRecord::Base
belongs_to :user
attr_accessible :user_id, :name, :url, :company, :location
end
class User < ActiveRecord::Base
has_one :profile, :dependent => :destroy
# Include default devise modules. Others available are:
# :http_authenticatable, :token_authenticatable, :confirmable, :lockable, :timeoutable and :activatable
devise :registerable, :database_authenticatable, :recoverable,
:rememberable, :trackable, :validatable
# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :profile_attributes
accepts_nested_attributes_for :profile
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment