Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. class User < ActiveRecord::Base
  2. attr_accessible :email, :name, :password, :username
  3. validates_presence_of :email, :name, :password, :username
  4. end
  5.  
  6. class SignupController < ApplicationController
  7. def init
  8. @user = User.new
  9. render :template => '/signup/signup'
  10. end
  11.  
  12. def signup
  13. @user = User.new(params[:user])
  14. if @user.valid?
  15. @user.save
  16. render :template => '/signup/success'
  17. else
  18. #bla bla bla
  19. end
  20. end
  21. end
  22.  
  23. <h1>Signup!!!</h1>
  24. <%= form_for(@user, :url => signup_path) do |f| %>
  25. Name: <%= f.text_field :name %> </br>
  26. Email <%= f.text_field :email %> </br>
  27. Username: <%= f.text_field :username %> </br>
  28. Password: <%= f.text_field :password %> </br>
  29. <%= submit_tag "Submit" %>
  30. <% end %>
  31.  
  32. <h1>signup successfull :) </h1>
  33.  
  34. get '/index/signup' => 'signup#init', :as => :signup_index
  35. post '/index/signup/' => 'signup#signup', :as => :signup
  36.  
  37. gem 'strong_parameters'
  38.  
  39. class User < ActiveRecord::Base
  40. include ActiveModel::ForbiddenAttributesProtection
  41. validates_presence_of :email, :name, :password, :username
  42. end
  43.  
  44. class UsersController < ApplicationController
  45. def new
  46. @user = User.new
  47. end
  48.  
  49. def create
  50. @user = User.new(user_params)
  51. if @user.save
  52. redirect_to login_path, :notice => "You have signed up successfully. You may now login!"
  53. else
  54. render :new, :alert => "There was an problem creating your account"
  55. end
  56. end
  57.  
  58. private
  59.  
  60. def user_params
  61. params.require(:user).permit(:email, :name, :password, :username)
  62. end
  63. end
  64.  
  65. <h1>Signup!!</h1>
  66. <%= render :partial => "form" %>
  67.  
  68. <%= form_for @user do |f| %>
  69. <%= f.label :name %>
  70. <%= f.text_field :name %><br />
  71.  
  72. <%= f.label :email, "Email Address" %>
  73. <%= f.email_field :email %><br />
  74.  
  75. <%= f.label :username %>
  76. <%= f.text_field :username %><br />
  77.  
  78. <%= f.label :password %>
  79. <%= f.password_field :password %><br />
  80.  
  81. <%= f.submit "Sign Up" %>
  82. <% end %>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement