Advertisement
Guest User

Untitled

a guest
Mar 28th, 2016
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.97 KB | None | 0 0
  1. class CreateUsers < ActiveRecord::Migration
  2. def change
  3. create_table :users do |t|
  4. t.string :name
  5. t.string :email
  6. t.string :password
  7.  
  8. t.timestamps null: false
  9. end
  10. end
  11. end
  12.  
  13. class User < ActiveRecord::Base
  14. begin
  15. attr_accessor :name, :email, :password, :password_confirmation
  16. end
  17. validates :name, :presence => true, :uniqueness => true, :length => { :in => 3..20 }
  18. validates :email, :presence => true, :uniqueness => true
  19. validates :password, :confirmation => true #password_confirmation attr
  20. validates_length_of :password, :in => 3..20, :on => :create
  21. end
  22.  
  23. class UsersController < ApplicationController
  24. def login
  25.  
  26. end
  27.  
  28. def create
  29. flash[:notice] = ''
  30. @user=User.new(user_params)
  31. if @user.valid?
  32. @user.save
  33. flash[:notice] = "You signed up successfully"
  34. render 'users/login'
  35. else
  36. flash[:error] = "Form is invalid"
  37. render 'users/signup'
  38. end
  39.  
  40. end
  41.  
  42.  
  43. def signup
  44. @user = User.new
  45. flash[:notice]=''
  46. flash[:error]=''
  47. end
  48.  
  49. private
  50. def user_params
  51. params.require(:user).permit(:name, :email, :password, :password_confirmation)
  52. end
  53.  
  54. end
  55.  
  56. <div class = "content">
  57. <h1>Sign Up</h1>
  58. <p>Maecenas nisi nunc, vulputate ac tempus eget, suscipit ut sapien. Aenean fringilla ultricies ultricies.
  59. Mauris aliquet nunc in velit posuere, in convallis purus ullamcorper.
  60. Nam imperdiet lacus lacus, quis finibus diam dapibus a. Nullam quis accumsan libero. </p>
  61.  
  62. <div class = "form_data">
  63. <%= form_for(:user, :url => {:controller => 'users', :action => 'create'}) do |f| %>
  64. <table>
  65. <tbody>
  66. <tr>
  67. <td> Name : </td>
  68. <td> <%= f.text_field :name %> </td>
  69. </tr>
  70. <tr>
  71. <td> Email : </td>
  72. <td> <%= f.text_field :email %> </td>
  73. </tr>
  74. <tr>
  75. <td> Password : </td>
  76. <td> <%= f.password_field :password %> </td>
  77. </tr>
  78. <tr>
  79. <td> Re-type Password : </td>
  80. <td> <%= f.password_field :password_confirmation %> </td>
  81. </tr>
  82. <tr>
  83. <td> </td>
  84. <td> <%= f.submit :signup %> </td>
  85. </tr>
  86.  
  87. </tbody>
  88. </table>
  89. <% end %>
  90.  
  91. </div>
  92. <% flash.each do |name, msg| %>
  93. <%= content_tag :div, msg, :id => "flash_#{name}" %>
  94. <% end %>
  95.  
  96. </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement