Advertisement
Guest User

Untitled

a guest
Jul 30th, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.97 KB | None | 0 0
  1. ************* CONTROLLER ****************
  2.  
  3. def signup
  4. case request.method
  5. when :get
  6. @account_holder = AccountHolder.new
  7. @account = Account.new
  8. @blog = Blog.new
  9. return true
  10. when :post
  11. @account = Account.new(params[:account])
  12. @account_holder = AccountHolder.new(params[:account_holder])
  13. @blog = Blog.new(params[:blog])
  14.  
  15. @plan = Plan.find_by_name('free')
  16. @administrator = Role.find_by_name('administrator')
  17.  
  18. @account_holder.display_name = params[:account_holder][:first_name] " " params[:account_holder][:last_name]
  19.  
  20. begin
  21. Account.transaction do
  22. # account > subscription < plan
  23. @account.subscriptions.create(:plan => @plan)
  24. @account.save!
  25.  
  26. # account_holder > membership < group
  27. #@account_holder.account = @account
  28. #@account_holder.assignments.create(:role => @administrator)
  29. @account_holder.save!
  30.  
  31. # blog > membership < group
  32. #@blog.users << @account_holder
  33. @blog.save!
  34. end
  35. rescue Exception => e
  36. #logger.error("message for the log file #{e.message}")
  37. #flash[:notice] = e.message
  38. redirect_to :action => 'signup' and return
  39. end
  40. redirect_to :action => 'list'
  41. end
  42. end
  43.  
  44.  
  45.  
  46. ************* VIEW ******************
  47.  
  48. <%= error_messages_for :account %>
  49. <%= error_messages_for :account_holder %>
  50. <%= error_messages_for :blog %>
  51. <% form_for :account, @account, :url => { :action => "signup" } do |af| %>
  52. <% fields_for :account_holder, @account_holder do |ahf| -%>
  53. <fieldset>
  54. <legend>Your Details</legend>
  55. <label for="acount_holder_first_name">First Name: <%= ahf.text_field :first_name %></label><br />
  56. <label for="account_holder_last_name">Last Name: <%= ahf.text_field :last_name %></label><br />
  57. <label for="account_holder_username">Prefered Username: <%= ahf.text_field :username %></label><br />
  58. <label for="account_holder_email">Email: <%= ahf.text_field :email %></label><br />
  59. <label for="account_holder_email_confirmation">Email Confirmation: <%= ahf.text_field :email_confirmation %></label><br />
  60. <label for="account_holder_password">Password: <%= ahf.password_field :password %></label><br />
  61. <label for="account_holder_password_confirmation">Confirm Password: <%= ahf.password_field :password_confirmation %></label><br />
  62. <label for="account_holder_terms_of_acceptance">Accept Terms?: <%= ahf.check_box :terms_of_acceptance %></label>
  63. </fieldset>
  64. <% end -%>
  65. <fieldset>
  66. <legend>Your application details</legend>
  67. <% fields_for :blog, @blog do |blog| -%>
  68. <label for="blog_domain_name">Where would you like your blog? <%= blog.text_field :domain_name %>.mynewsite.com</label>
  69. <% end -%>
  70. </fieldset>
  71. <%= submit_tag %>
  72. <% end %>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement