Class: Wco::ProfilesController

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

Instance Method Summary collapse

Methods inherited from ApplicationController

#home, #tinymce

Methods included from ApplicationHelper

#my_truthy?, #obfuscate, #pp_amount, #pp_currency, #pp_date, #pp_datetime, #pp_money, #pp_percent, #pp_time, #pretty_date

Instance Method Details

#createObject



4
5
6
7
8
9
10
11
12
13
14
# File 'app/controllers/wco/profiles_controller.rb', line 4

def create
  @profile = Wco::Profile.new params[:profile].permit!
  authorize! :create, @profile
  if @profile.save
    flash_notice @profile
    redirect_to action: :index
  else
    flash_alert @profile
    render action: 'new'
  end
end

#editObject



16
17
18
19
# File 'app/controllers/wco/profiles_controller.rb', line 16

def edit
  @profile = Wco::Profile.find params[:id]
  authorize! :update, @profile
end

#indexObject



21
22
23
24
25
26
27
28
# File 'app/controllers/wco/profiles_controller.rb', line 21

def index
  @profiles = Wco::Profile.all
  authorize! :index, Wco::Profile
  if params[:q]
    q = URI.decode(params[:q])
    @profiles = @profiles.where({ email: /#{q}/i })
  end
end

#newObject



30
31
32
33
# File 'app/controllers/wco/profiles_controller.rb', line 30

def new
  @new_profile = Wco::Profile.new
  authorize! :new, @new_profile
end

#updateObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/controllers/wco/profiles_controller.rb', line 35

def update
  @profile = Wco::Profile.find params[:id]
  authorize! :update, @profile

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

  flag = @profile.update 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