Sha256: 63e3ff8ba2192e5b7ba0e6f6679382fdf08b21713e81160914491e77612b4bfa

Contents?: true

Size: 1.54 KB

Versions: 122

Compression:

Stored size: 1.54 KB

Contents

class IshManager::UserProfilesController < IshManager::ApplicationController

  before_action :set_lists

  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

122 entries across 122 versions & 1 rubygems

Version Path
ish_manager-0.1.8.245 app/controllers/ish_manager/user_profiles_controller.rb
ish_manager-0.1.8.244 app/controllers/ish_manager/user_profiles_controller.rb
ish_manager-0.1.8.243 app/controllers/ish_manager/user_profiles_controller.rb
ish_manager-0.1.8.242 app/controllers/ish_manager/user_profiles_controller.rb
ish_manager-0.1.8.241 app/controllers/ish_manager/user_profiles_controller.rb
ish_manager-0.1.8.239 app/controllers/ish_manager/user_profiles_controller.rb
ish_manager-0.1.8.238 app/controllers/ish_manager/user_profiles_controller.rb
ish_manager-0.1.8.237 app/controllers/ish_manager/user_profiles_controller.rb
ish_manager-0.1.8.236 app/controllers/ish_manager/user_profiles_controller.rb
ish_manager-0.1.8.235 app/controllers/ish_manager/user_profiles_controller.rb
ish_manager-0.1.8.234 app/controllers/ish_manager/user_profiles_controller.rb
ish_manager-0.1.8.233 app/controllers/ish_manager/user_profiles_controller.rb
ish_manager-0.1.8.232 app/controllers/ish_manager/user_profiles_controller.rb
ish_manager-0.1.8.231 app/controllers/ish_manager/user_profiles_controller.rb
ish_manager-0.1.8.230 app/controllers/ish_manager/user_profiles_controller.rb
ish_manager-0.1.8.229 app/controllers/ish_manager/user_profiles_controller.rb
ish_manager-0.1.8.228 app/controllers/ish_manager/user_profiles_controller.rb
ish_manager-0.1.8.227 app/controllers/ish_manager/user_profiles_controller.rb
ish_manager-0.1.8.226 app/controllers/ish_manager/user_profiles_controller.rb
ish_manager-0.1.8.225 app/controllers/ish_manager/user_profiles_controller.rb