Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ************* CONTROLLER ****************
- def signup
- case request.method
- when :get
- @account_holder = AccountHolder.new
- @account = Account.new
- @blog = Blog.new
- return true
- when :post
- @account = Account.new(params[:account])
- @account_holder = AccountHolder.new(params[:account_holder])
- @blog = Blog.new(params[:blog])
- @plan = Plan.find_by_name('free')
- @administrator = Role.find_by_name('administrator')
- @account_holder.display_name = params[:account_holder][:first_name] " " params[:account_holder][:last_name]
- begin
- Account.transaction do
- # account > subscription < plan
- @account.subscriptions.create(:plan => @plan)
- @account.save!
- # account_holder > membership < group
- #@account_holder.account = @account
- #@account_holder.assignments.create(:role => @administrator)
- @account_holder.save!
- # blog > membership < group
- #@blog.users << @account_holder
- @blog.save!
- end
- rescue Exception => e
- #logger.error("message for the log file #{e.message}")
- #flash[:notice] = e.message
- redirect_to :action => 'signup' and return
- end
- redirect_to :action => 'list'
- end
- end
- ************* VIEW ******************
- <%= error_messages_for :account %>
- <%= error_messages_for :account_holder %>
- <%= error_messages_for :blog %>
- <% form_for :account, @account, :url => { :action => "signup" } do |af| %>
- <% fields_for :account_holder, @account_holder do |ahf| -%>
- <fieldset>
- <legend>Your Details</legend>
- <label for="acount_holder_first_name">First Name: <%= ahf.text_field :first_name %></label><br />
- <label for="account_holder_last_name">Last Name: <%= ahf.text_field :last_name %></label><br />
- <label for="account_holder_username">Prefered Username: <%= ahf.text_field :username %></label><br />
- <label for="account_holder_email">Email: <%= ahf.text_field :email %></label><br />
- <label for="account_holder_email_confirmation">Email Confirmation: <%= ahf.text_field :email_confirmation %></label><br />
- <label for="account_holder_password">Password: <%= ahf.password_field :password %></label><br />
- <label for="account_holder_password_confirmation">Confirm Password: <%= ahf.password_field :password_confirmation %></label><br />
- <label for="account_holder_terms_of_acceptance">Accept Terms?: <%= ahf.check_box :terms_of_acceptance %></label>
- </fieldset>
- <% end -%>
- <fieldset>
- <legend>Your application details</legend>
- <% fields_for :blog, @blog do |blog| -%>
- <label for="blog_domain_name">Where would you like your blog? <%= blog.text_field :domain_name %>.mynewsite.com</label>
- <% end -%>
- </fieldset>
- <%= submit_tag %>
- <% end %>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement