Class: IshManager::UserProfilesController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- IshManager::UserProfilesController
- Defined in:
- app/controllers/ish_manager/user_profiles_controller.rb
Instance Method Summary collapse
Methods inherited from ApplicationController
Instance Method Details
#create ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'app/controllers/ish_manager/user_profiles_controller.rb', line 52 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! :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.} profile errors: #{@user_profile.errors.}" end if @user_profile.save flash[:notice] = "Created profile" else flash[:alert] = "Cannot create profile: #{@user_profile.errors.}" end redirect_to :action => :index end |
#edit ⇒ Object
19 20 21 22 |
# File 'app/controllers/ish_manager/user_profiles_controller.rb', line 19 def edit @profile = Ish::UserProfile.find params[:id] :edit, @profile end |
#index ⇒ Object
6 7 8 9 10 11 12 |
# File 'app/controllers/ish_manager/user_profiles_controller.rb', line 6 def index @user_profiles = Ish::UserProfile.all :index, Ish::UserProfile if params[:q] @user_profiles = @user_profiles.where({ :email => /#{params[:q]}/i }) end end |
#new ⇒ Object
47 48 49 50 |
# File 'app/controllers/ish_manager/user_profiles_controller.rb', line 47 def new @profile = Ish::UserProfile.new :new, @profile end |
#show ⇒ Object
14 15 16 17 |
# File 'app/controllers/ish_manager/user_profiles_controller.rb', line 14 def show @profile = Ish::UserProfile.find params[:id] :show, @profile end |
#update ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'app/controllers/ish_manager/user_profiles_controller.rb', line 24 def update @profile = Ish::UserProfile.find params[:id] :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.}" end if params[:redirect_to] redirect_to params[:redirect_to] else redirect_to :action => :index end end |