Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class CreateUsers < ActiveRecord::Migration
- def change
- create_table :users do |t|
- t.string :name
- t.string :email
- t.string :password
- t.timestamps null: false
- end
- end
- end
- class User < ActiveRecord::Base
- begin
- attr_accessor :name, :email, :password, :password_confirmation
- end
- validates :name, :presence => true, :uniqueness => true, :length => { :in => 3..20 }
- validates :email, :presence => true, :uniqueness => true
- validates :password, :confirmation => true #password_confirmation attr
- validates_length_of :password, :in => 3..20, :on => :create
- end
- class UsersController < ApplicationController
- def login
- end
- def create
- flash[:notice] = ''
- @user=User.new(user_params)
- if @user.valid?
- @user.save
- flash[:notice] = "You signed up successfully"
- render 'users/login'
- else
- flash[:error] = "Form is invalid"
- render 'users/signup'
- end
- end
- def signup
- @user = User.new
- flash[:notice]=''
- flash[:error]=''
- end
- private
- def user_params
- params.require(:user).permit(:name, :email, :password, :password_confirmation)
- end
- end
- <div class = "content">
- <h1>Sign Up</h1>
- <p>Maecenas nisi nunc, vulputate ac tempus eget, suscipit ut sapien. Aenean fringilla ultricies ultricies.
- Mauris aliquet nunc in velit posuere, in convallis purus ullamcorper.
- Nam imperdiet lacus lacus, quis finibus diam dapibus a. Nullam quis accumsan libero. </p>
- <div class = "form_data">
- <%= form_for(:user, :url => {:controller => 'users', :action => 'create'}) do |f| %>
- <table>
- <tbody>
- <tr>
- <td> Name : </td>
- <td> <%= f.text_field :name %> </td>
- </tr>
- <tr>
- <td> Email : </td>
- <td> <%= f.text_field :email %> </td>
- </tr>
- <tr>
- <td> Password : </td>
- <td> <%= f.password_field :password %> </td>
- </tr>
- <tr>
- <td> Re-type Password : </td>
- <td> <%= f.password_field :password_confirmation %> </td>
- </tr>
- <tr>
- <td> </td>
- <td> <%= f.submit :signup %> </td>
- </tr>
- </tbody>
- </table>
- <% end %>
- </div>
- <% flash.each do |name, msg| %>
- <%= content_tag :div, msg, :id => "flash_#{name}" %>
- <% end %>
- </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement