Advertisement
Guest User

payview

a guest
Dec 22nd, 2016
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rails 1.94 KB | None | 0 0
  1. <h1>Users#new</h1>
  2. <p>Find me in app/views/users/new.html.erb</p>
  3.  
  4. <h1>Create a new Account</h1>
  5. <div class="">
  6.   <%= form_for @user do |f|%>
  7.     Complete Name: <%= f.text_field :name %>
  8.     Age: <%= f.number_field :age %>
  9.     Username: <%= f.text_field :username %>
  10.     Email: <%= f.email_field :email %>
  11.     Password: <%= f.password_field :password %>
  12.     Password Confirmation: <%= f.password_field :password_confirmation %>
  13.     <%= f.submit "Create Account" %>
  14.   <% end %>
  15. </div>
  16.  
  17.  
  18. class UsersController < ApplicationController
  19.  
  20.   def index
  21.     @users = User.all
  22.   end
  23.  
  24.   def show
  25.     @user = User.find(params[:id])
  26.   end
  27.  
  28.   def new
  29.     @user = User.new
  30.   end
  31.  
  32.   def create
  33.     @user = User.new(secure_params)
  34.     if @user.save
  35.       flash[:success] = "You account has been created Successfully"
  36.       redirect_to user_path(@user)
  37.     else
  38.       @user.errors.inspect
  39.       render :new
  40.     end
  41.   end
  42.  
  43.   def edit
  44.  
  45.   end
  46.  
  47.   def update
  48.   end
  49.  
  50.   def destroy
  51.   end
  52.  
  53.   private
  54.   # It will only permit those parameters to come from the view
  55.   def secure_params
  56.     params.require(:user).permit(:name,:email,:username,:password,:password_confirmation, :age)
  57.   end
  58. end
  59.  
  60.  
  61. class User < ActiveRecord::Base
  62.   has_secure_password
  63.   validates :name, :username,:email, :age, :password,:password_confirmation, presence: true
  64.   validates :email, :username, uniqueness: true
  65.   validates :age, numericality: {only_integer: true}
  66.   validates :password, length: {in: 6..20}
  67. end
  68.  
  69.  
  70.  
  71. <!DOCTYPE html>
  72. <html>
  73. <head>
  74.   <title>PayAndWatch</title>
  75.   <%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track' => true %>
  76.   <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
  77.   <%= csrf_meta_tags %>
  78. </head>
  79. <body>
  80.   <div class="container-fluid">
  81.     <%= flash.each do |key, value| %>
  82.       <h2> <%= key + value %> </h2>
  83.     <% end %>
  84.     <%= yield %>
  85.   </div>
  86.  
  87. </body>
  88. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement