Sha256: a12628882eb51554ee2c2c3a3bb8c6294faa117121defdfb0b6882c8523fc138

Contents?: true

Size: 1.52 KB

Versions: 25

Compression:

Stored size: 1.52 KB

Contents

class IshManager::UserProfilesController < IshManager::ApplicationController

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

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

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

  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

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

  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

end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
ish_manager-0.1.8.105 app/controllers/ish_manager/user_profiles_controller.rb
ish_manager-0.1.8.104 app/controllers/ish_manager/user_profiles_controller.rb
ish_manager-0.1.8.103 app/controllers/ish_manager/user_profiles_controller.rb
ish_manager-0.1.8.102 app/controllers/ish_manager/user_profiles_controller.rb
ish_manager-0.1.8.101 app/controllers/ish_manager/user_profiles_controller.rb
ish_manager-0.1.8.100 app/controllers/ish_manager/user_profiles_controller.rb
ish_manager-0.1.8.99 app/controllers/ish_manager/user_profiles_controller.rb
ish_manager-0.1.8.98 app/controllers/ish_manager/user_profiles_controller.rb
ish_manager-0.1.8.97 app/controllers/ish_manager/user_profiles_controller.rb
ish_manager-0.1.8.96 app/controllers/ish_manager/user_profiles_controller.rb
ish_manager-0.1.8.95 app/controllers/ish_manager/user_profiles_controller.rb
ish_manager-0.1.8.94 app/controllers/ish_manager/user_profiles_controller.rb
ish_manager-0.1.8.93 app/controllers/ish_manager/user_profiles_controller.rb
ish_manager-0.1.8.92 app/controllers/ish_manager/user_profiles_controller.rb
ish_manager-0.1.8.91 app/controllers/ish_manager/user_profiles_controller.rb
ish_manager-0.1.8.90 app/controllers/ish_manager/user_profiles_controller.rb
ish_manager-0.1.8.89 app/controllers/ish_manager/user_profiles_controller.rb
ish_manager-0.1.8.88 app/controllers/ish_manager/user_profiles_controller.rb
ish_manager-0.1.8.87 app/controllers/ish_manager/user_profiles_controller.rb
ish_manager-0.1.8.86 app/controllers/ish_manager/user_profiles_controller.rb