Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Add a new page to our site, signup.erb
- ```
- <form action="/signup" method="post">
- <label for="email">Email:</label>
- <input type="text" name="email" id="email">
- <label for="password">Password</label>
- <input type="password" name="password" id="password">
- <input type="submit">
- </form>
- ```
- Recieving Data
- ```
- # get signup (handles when users browse to signup page)
- get '/signup' do
- @user = User.new
- erb :signup
- end
- # post stuff (handles when users try and signup to our site)
- post '/signup' do
- email = params[:email]
- password = params[:password]
- @user = User.new({ email: email, password: password })
- # runs our validation and returns a boolean
- if @user.save()
- redirect '/'
- else
- erb :signup
- end
- end
- ```
- Validation helps make sure bad data isn't being put into our database
- ```
- class User < ActiveRecord::Base
- validates :username, :email, presence: true
- validates :email, uniqueness: true
- end
- ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement