Module: TinyCore::Controllers::Users

Defined in:
lib/tiny_core/controllers/users.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(receiver) ⇒ Object



4
5
6
# File 'lib/tiny_core/controllers/users.rb', line 4

def self.included(receiver)
  receiver.before_filter :login_required, :only => [:index, :show, :edit, :update]
end

Instance Method Details

#createObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/tiny_core/controllers/users.rb', line 16

def create
  if logged_in? && current_user.respond_to?(:current_account)
    @user = current_user..users.build(params[:user])
    @user. = current_user.
  else
    @user = User.new(params[:user])
  end

  if @user.save
    flash[:notice] = I18n.t('flash.notice.created_user')

    if logged_in?
      @user.accounts << current_user. if current_user.respond_to?(:current_account)
      redirect_to new_user_path
    else
      redirect_back_or_default root_path
    end
  else
    render :action => :new
  end
end

#editObject



42
43
44
# File 'lib/tiny_core/controllers/users.rb', line 42

def edit
  @user = User.find(params[:id])
end

#indexObject



8
9
10
# File 'lib/tiny_core/controllers/users.rb', line 8

def index
  redirect_to (current_user.)
end

#newObject



12
13
14
# File 'lib/tiny_core/controllers/users.rb', line 12

def new
  @user = User.new
end

#showObject



38
39
40
# File 'lib/tiny_core/controllers/users.rb', line 38

def show
  @user = User.find(params[:id])
end

#updateObject



46
47
48
49
50
51
52
53
54
# File 'lib/tiny_core/controllers/users.rb', line 46

def update
  @user = User.find(params[:id])
  if @user.update_attributes(params[:user])
    flash[:notice] = I18n.t('flash.notice.updated_user')
    redirect_to root_path
  else
    render :action => :edit
  end
end