Here is my controller’s code:
=======
def new
@user = User.new
@code = params[:invite_code]
if params[:invite_code].nil?
@invite = Invite.new
else
@invite = Invite.find_by_invite_code(params[:invite_code])
end
end
def create
if params[:invite][:invite_code].empty?
flash[:error] = "You need the invite code"
render :action => 'new'
return
end
@code = params[:invite][:invite_code]
if params[:user][:email].empty?
flash[:error] = "Please enter your email address"
render :action => 'new'
return
end
@user = User.new(params[:user])
flash[:error] = nil
if @user.save!
self.current_user = @user
redirect_back_or_default('/')
flash[:notice] = "Thanks for signing up!"
end
rescue ActiveRecord::RecordInvalid
render :action => ‘new’
end
And here is my view:
Sign Up
<% form_for :user, @user, :url => users_path do |f| -%>
<div class="form_item">
<label for="invite_code">Enter your Invitation Code</label><br />
<%= text_field :invite, :invite_code %>
</div>
<fieldset>
<legend>Personal Details</legend>
<div class="form_item">
<label for="username">Username</label><br />
<%= f.text_field :username, :class => 'input_text' %>
<%= error_for_field :user, :username %>
</div>
<div class="form_item">
<label for="email">Email</label><br/>
<%= f.text_field :email, :class => 'input_text' %>
<%= (error_for_field :user, :email) %>
</div>
<div class="form_item">
<label for="password">Password</label><br/>
<%= f.password_field :password, :class => 'input_text' %>
<%= (error_for_field :user, :password) %>
</div>
<div class="form_item">
<label for="password_confirmation">Confirm Password</label><br/>
<%= f.password_field :password_confirmation, :class =>
‘input_text’ %>
<%= (error_for_field :user, :password_confirmation) %>
<div class="form_item">
<label for="first_name">First Name</label><br/>
<%= f.text_field :first_name, :class => 'input_text' %>
</div>
<div class="form_item">
<label for="last_name">Last Name</label><br/>
<%= f.text_field :last_name, :class => 'input_text' %>
</div>
<div class="form_item">
<label for="birthday">The day you were born</label><br/>
<%= f.date_select :birthday, :start_year => 1945, :end_year =>
Time.now.year,
:order => [:day,:month,:year], :include_blank => true, :class =>
‘input_select’ %>
<%= error_for_field :user, :birthday %>
<div class="form_item">
<label for="gender">Gender</label><br/>
<%= f.select :gender, [["Male", "M"], ["Female", "F"]],
{ :include_blank => true }, :class => ‘input_select’ %>
</fieldset>
<div class="form_item">
<%= submit_tag 'Sign up', :class => 'input_button' %>
</div>
<% end -%>
Any help would be much appreciated.
Thanks !