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



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'app/controllers/ish_manager/user_profiles_controller.rb', line 49

def create
  @user = User.find_or_create_by( :email => params[:profile][:email] )
  @user.password ||= (0...12).map { rand(100) }.join
  @user_profile = Ish::UserProfile.new params[:profile].permit!
  authorize! :create, @user_profile

  if params[:photo]
    photo = Photo.new :photo => params[:photo]
    @user_profile.profile_photo = photo
  end

  if !@user.save
    raise "cannot save profile.user: #{@user.errors.full_messages} profile errors: #{@user_profile.errors.full_messages}"
  end
  if @user_profile.save
    flash[:notice] = "Created profile"
  else
    flash[:alert] = "Cannot create profile: #{@user_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 = Ish::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 = Ish::UserProfile.all
  authorize! :index, Ish::UserProfile
end

#newObject



44
45
46
47
# File 'app/controllers/ish_manager/user_profiles_controller.rb', line 44

def new
  @profile = Ish::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 = Ish::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
36
37
38
39
40
41
42
# File 'app/controllers/ish_manager/user_profiles_controller.rb', line 21

def update
  @profile = Ish::UserProfile.find params[:id]
  authorize! :update, @profile

  if params[:photo]
    photo = Photo.new :photo => params[:photo]
    @profile.profile_photo = photo
  end

  flag = @profile.update_attributes params[:profile].permit!

  if flag
    flash[:notice] = "Updated profile #{@profile.email}"
  else
    flash[:alert] = "Cannot update profile: #{@profile.errors.full_messages}"
  end
  if params[:redirect_to]
    redirect_to params[:redirect_to]
  else
    redirect_to :action => :index
  end
end