Guest User

Untitled

a guest
May 3rd, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1.  
  2. ## UserController
  3. def new
  4. @user = User.new
  5. @artist = Artist.new
  6. end
  7.  
  8. def create
  9. logout_keeping_session!
  10. @user = User.new(params[:user])
  11. @artist = @user.build_artist(params[:artist])
  12. @user.register! if @user && @user.valid?
  13. success = @user && @user.valid?
  14. if success && @user.errors.empty?
  15. redirect_back_or_default('/')
  16. flash[:notice] = "Thanks for signing up! We're sending you an email with your activation code."
  17. else
  18. flash[:error] = "We couldn't set up that account, sorry. Please try again, or contact an admin (link is above)."
  19. render :action => 'new'
  20. end
  21. end
  22.  
  23.  
  24. ## Artist Model
  25.  
  26. class Artist < ActiveRecord::Base
  27. validates_presence_of :name
  28. validates_uniqueness_of :name, :case_sensitive => false
  29. end
  30.  
  31.  
  32.  
  33. ## User:View:New
  34.  
  35. <h1>Sign up as a new user</h1>
  36. <% @user.password = @user.password_confirmation = nil %>
  37.  
  38. <%= error_messages_for :user %>
  39. <% form_for :user, :url => users_path do |f| -%>
  40. <p><label for="email">Email (this will be your login name)</label><br/>
  41. <%= f.text_field :email %></p>
  42.  
  43. <p><label for="name">Artist Name</label><br/>
  44. <% fields_for "artist", @artist do |a| %>
  45. <%= a.text_field :name %>
  46. <% end %>
  47. <p><label for="password">Password</label><br/>
  48. <%= f.password_field :password %></p>
  49.  
  50. <p><label for="password_confirmation">Confirm Password</label><br/>
  51. <%= f.password_field :password_confirmation %></p>
  52.  
  53. <p><%= submit_tag 'Sign up' %></p>
  54. <% end -%>
Add Comment
Please, Sign In to add comment