Class: IshManager::UserProfilesController

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

Instance Method Summary collapse

Methods inherited from ApplicationController

#home

Instance Method Details

#createObject



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/controllers/ish_manager/user_profiles_controller.rb', line 42

def create
  @profile = IshModels::UserProfile.new params[:profile].permit!
  authorize! :create, @profile
  @profile.user = User.find_or_create_by( :email => params[:profile][:email] )
  @profile.user.password ||= (0...12).map { rand(100) }.join
  if !@profile.user.save
    puts! @profile.user.errors.messages
    raise 'cannot save profile.user'
  end
  if @profile.save
    flash[:notice] = "Created profile"
  else
    flash[:alert] = "Cannot create profile: #{@profile.errors.messages}"
  end
  redirect_to :action => :index
end

#editObject



16
17
18
19
# File 'app/controllers/ish_manager/user_profiles_controller.rb', line 16

def edit
  @profile = IshModels::UserProfile.find params[:id]
  authorize! :edit, @profile
end

#indexObject



6
7
8
9
# File 'app/controllers/ish_manager/user_profiles_controller.rb', line 6

def index
  @user_profiles = IshModels::UserProfile.all.includes( :user )
  authorize! :index, IshModels::UserProfile
end

#newObject



37
38
39
40
# File 'app/controllers/ish_manager/user_profiles_controller.rb', line 37

def new
  @profile = IshModels::UserProfile.new
  authorize! :new, @profile
end

#showObject



11
12
13
14
# File 'app/controllers/ish_manager/user_profiles_controller.rb', line 11

def show
  @user_profile = IshModels::UserProfile.find params[:id]
  authorize! :show, @user_profile
end

#updateObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/controllers/ish_manager/user_profiles_controller.rb', line 21

def update
  @profile = IshModels::UserProfile.find params[:id]
  authorize! :update, @profile
  flag = @profile.update_attributes params[:profile].permit!
  if flag
    flash[:notice] = "Updated profile #{@profile.email}"
  else
    flash[:alert] = "Cannot update profile: #{pp_errors @profile.errors.messages}"
  end
  if params[:redirect_to]
    redirect_to params[:redirect_to]
  else
    redirect_to :action => :index
  end
end