Class: UserController

Inherits:
ApplicationController show all
Defined in:
app/controllers/user_controller.rb

Constant Summary

Constants included from PaginationHelper

PaginationHelper::DEFAULT_OPTIONS, PaginationHelper::OPTIONS

Instance Method Summary collapse

Methods included from PaginationHelper

included, #paginate, validate_options!

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
# File 'app/controllers/user_controller.rb', line 9

def method_missing(method)
  @user  = User.find_by_username(method.to_s)
redirect_to_main and return unless @user

  @post_pages, @posts = paginate :posts,
                                 :conditions => ['user_id = ?', @user.id],
                                 :order_by   => 'created_at DESC', 
                                 :per_page   => @user.posts_per_page
                                 
  render 'post/index'
end

Instance Method Details

#destroyObject



39
40
41
42
# File 'app/controllers/user_controller.rb', line 39

def destroy
  User.find(@params['id']).destroy rescue nil
  redirect_to_user
end

#indexObject



5
6
7
# File 'app/controllers/user_controller.rb', line 5

def index
  @users = User.find_all nil, 'username'
end

#listObject

Administrative functions.



23
24
25
# File 'app/controllers/user_controller.rb', line 23

def list
  @users = User.find_all(nil, 'username')
end

#newObject



27
28
29
30
31
32
33
34
35
36
37
# File 'app/controllers/user_controller.rb', line 27

def new
  @user = User.new
  if @request.post?
    @user.attributes = @params['user']
    if @user.save
      flash['notice'] = "User was successfully saved."
      redirect_to_user
      return
    end
  end
end