recitation4 notes

Rb class sessionscontroller applicationcontroller def

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ake db:migrate app/models/user.rb class User < ActiveRecord::Base attr_accessible :email, :password, :password_confirmation has_secure_password validates_presence_of :password, :on => :create end The attr_accessible statement prevents the password_digest from being set from the user registration form. Create a users controller rails generate controller users app/controllers/users_controller.rb class UsersController < ApplicationController def new @user = end def create @user =[:user]) if redirect_to root_url, :notice => “You are signed up.” else render “new” end end end Inside app/views/users/new.html.erb <h1>Sign Up</h1> <%= form_for @user do |form| %> <div class=“field”> 5 <%= f.label :email %> <%= f.text_field :email %> </div> <div class= “field”> <%= f.label :password %> <%= f.text_field :password %> </div> <div class = “field”> <%= f.label :password_confirmation %> <%= f.text_field :password_confirmation %> </div> <div class= “actions”> <%= f.submit %> </div> <% end %> We also need to let users log in, not just sign up. When we log a user in, though, we’re not creating a new user -- we’re creating a new session. We’ll create a controller to handle sessions. rails generate controller sessions app/controllers/sessions_controller.rb class SessionsController < ApplicationController def new end def create user = User.find_by_email(params[:email]) if...
View Full Document

This document was uploaded on 03/18/2014 for the course EECS 6.170 at MIT.

Ask a homework question - tutors are online