Created
March 26, 2011 11:02
-
-
Save Znow/888202 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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