Skip to content

Instantly share code, notes, and snippets.

@agibralter
Created October 11, 2008 22:30
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 agibralter/16334 to your computer and use it in GitHub Desktop.
Save agibralter/16334 to your computer and use it in GitHub Desktop.
#new-user
- form_for @user, :url => users_path do |f|
.email
%label{:for => "email"} email
= f.text_field :email
= f.error_message_on :email
.password
%label{:for => "password"} password
= f.password_field :password
= f.error_message_on :password
.password-confirmation
%label{:for => "password_confirmation"} confirm password
= f.password_field :password_confirmation
= f.error_message_on :password_confirmation
.user-profile
- f.fields_for @user.user_profile do |p|
.gender
%label{:for => "gender"} gender
= p.select :gender, select_opts(:gender)
= p.error_message_on :gender
.year
%label{:for => "year"} year
= p.select :year, select_opts(:year_of_birth)
= p.error_message_on :year
%div
= submit_tag 'join the urtak project'
class User < ActiveRecord::Base
# ...
has_one :user_profile
# ...
end
class UsersController < ApplicationController
before_filter :login_required, :except => [:new, :create]
def new
@user = User.new
@user.build_user_profile
end
def create
begin
@user = User.new(params[:user])
@user.build_user_profile(params[:user][:user_profile])
@user.save!
self.current_user = @user
flash[:notice] = "Thanks for signing up!"
redirect_to home_path
rescue
flash[:warning] = "Please fix the errors below."
render :action => 'new'
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment