Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <h1>Users#new</h1>
- <p>Find me in app/views/users/new.html.erb</p>
- <h1>Create a new Account</h1>
- <div class="">
- <%= form_for @user do |f|%>
- Complete Name: <%= f.text_field :name %>
- Age: <%= f.number_field :age %>
- Username: <%= f.text_field :username %>
- Email: <%= f.email_field :email %>
- Password: <%= f.password_field :password %>
- Password Confirmation: <%= f.password_field :password_confirmation %>
- <%= f.submit "Create Account" %>
- <% end %>
- </div>
- class UsersController < ApplicationController
- def index
- @users = User.all
- end
- def show
- @user = User.find(params[:id])
- end
- def new
- @user = User.new
- end
- def create
- @user = User.new(secure_params)
- if @user.save
- flash[:success] = "You account has been created Successfully"
- redirect_to user_path(@user)
- else
- @user.errors.inspect
- render :new
- end
- end
- def edit
- end
- def update
- end
- def destroy
- end
- private
- # It will only permit those parameters to come from the view
- def secure_params
- params.require(:user).permit(:name,:email,:username,:password,:password_confirmation, :age)
- end
- end
- class User < ActiveRecord::Base
- has_secure_password
- validates :name, :username,:email, :age, :password,:password_confirmation, presence: true
- validates :email, :username, uniqueness: true
- validates :age, numericality: {only_integer: true}
- validates :password, length: {in: 6..20}
- end
- <!DOCTYPE html>
- <html>
- <head>
- <title>PayAndWatch</title>
- <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
- <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
- <%= csrf_meta_tags %>
- </head>
- <body>
- <div class="container-fluid">
- <%= flash.each do |key, value| %>
- <h2> <%= key + value %> </h2>
- <% end %>
- <%= yield %>
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement