Skip to content

Instantly share code, notes, and snippets.

@Znow
Created March 26, 2011 11:02
Show Gist options
  • Select an option

  • Save Znow/888202 to your computer and use it in GitHub Desktop.

Select an option

Save Znow/888202 to your computer and use it in GitHub Desktop.
class UsersController < ApplicationController
include SessionsHelper
before_filter :authenticate, :only => [:index, :show, :edit, :update, :destroy]
before_filter :correct_user, :only => [:edit, :update]
before_filter :admin_user, :only => :destroy
before_filter :signed_in?, :only => [:new, :create]
def index
@title = "All users"
@users = User.paginate(:page => params[:page]) # Instead of .all, .paginate takes the records of the db in chunks, so only the the records that matches the page numbers gets printed
end
def create # When the form in the view is clicked
@user = User.new(params[:user])
if @user.save
sign_in @user
flash[:success] = "Welcome to DanielG.dk!"
redirect_to @user # Redirects to the new users show page
else
@title = "Sign Up"
render 'new'
end
end
def show
@user = User.find(params[:id]) # params[:id] is the same as User.find(1)
@title = @user.name
end
def new # Renders the new view
@user = User.new
@title = "Sign Up"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment