Class: IshManager::UserProfilesController
Instance Method Summary
collapse
#basic_auth, #home, #tinymce
Instance Method Details
#create ⇒ Object
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'app/controllers/ish_manager/user_profiles_controller.rb', line 6
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
|
#edit ⇒ Object
28
29
30
31
|
# File 'app/controllers/ish_manager/user_profiles_controller.rb', line 28
def edit
@profile = Ish::UserProfile.find params[:id]
authorize! :edit, @profile
end
|
#index ⇒ Object
33
34
35
36
37
38
39
|
# File 'app/controllers/ish_manager/user_profiles_controller.rb', line 33
def index
@user_profiles = Ish::UserProfile.all
authorize! :index, Ish::UserProfile
if params[:q]
@user_profiles = @user_profiles.where({ :email => /#{params[:q]}/i })
end
end
|
#new ⇒ Object
41
42
43
44
|
# File 'app/controllers/ish_manager/user_profiles_controller.rb', line 41
def new
@profile = Ish::UserProfile.new
authorize! :new, @profile
end
|
#show ⇒ Object
46
47
48
49
|
# File 'app/controllers/ish_manager/user_profiles_controller.rb', line 46
def show
@profile = Ish::UserProfile.find params[:id]
authorize! :show, @profile
end
|
#update ⇒ Object
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
# File 'app/controllers/ish_manager/user_profiles_controller.rb', line 51
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
puts! params[:profile][:customer_id].present?, 'params[:profile][:customer_id].present?'
if !params[:profile][:customer_id].present? || params[:delete_customer_id]
params[:profile][:customer_id] = nil
end
puts! params[:profile], 'ze params'
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 request.referrer
end
end
|