Sha256: de7db8df2b1aae37e474478da4c2cd4bf53ea8c3ee2e8dea45d8c65e7c489571

Contents?: true

Size: 1.76 KB

Versions: 74

Compression:

Stored size: 1.76 KB

Contents

class IshManager::UserProfilesController < IshManager::ApplicationController

  before_action :set_lists

  def index
    @user_profiles = Ish::UserProfile.all
    authorize! :index, Ish::UserProfile
  end

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

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

  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

    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 :action => :index
    end
  end

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

  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

end

Version data entries

74 entries across 74 versions & 1 rubygems

Version Path
ish_manager-0.1.8.397 app/controllers/ish_manager/user_profiles_controller.rb
ish_manager-0.1.8.396 app/controllers/ish_manager/user_profiles_controller.rb
ish_manager-0.1.8.395 app/controllers/ish_manager/user_profiles_controller.rb
ish_manager-0.1.8.394 app/controllers/ish_manager/user_profiles_controller.rb
ish_manager-0.1.8.393 app/controllers/ish_manager/user_profiles_controller.rb
ish_manager-0.1.8.392 app/controllers/ish_manager/user_profiles_controller.rb
ish_manager-0.1.8.391 app/controllers/ish_manager/user_profiles_controller.rb
ish_manager-0.1.8.390 app/controllers/ish_manager/user_profiles_controller.rb
ish_manager-0.1.8.389 app/controllers/ish_manager/user_profiles_controller.rb
ish_manager-0.1.8.388 app/controllers/ish_manager/user_profiles_controller.rb
ish_manager-0.1.8.387 app/controllers/ish_manager/user_profiles_controller.rb
ish_manager-0.1.8.386 app/controllers/ish_manager/user_profiles_controller.rb
ish_manager-0.1.8.385 app/controllers/ish_manager/user_profiles_controller.rb
ish_manager-0.1.8.384 app/controllers/ish_manager/user_profiles_controller.rb
ish_manager-0.1.8.383 app/controllers/ish_manager/user_profiles_controller.rb
ish_manager-0.1.8.382 app/controllers/ish_manager/user_profiles_controller.rb
ish_manager-0.1.8.381 app/controllers/ish_manager/user_profiles_controller.rb
ish_manager-0.1.8.380 app/controllers/ish_manager/user_profiles_controller.rb
ish_manager-0.1.8.379 app/controllers/ish_manager/user_profiles_controller.rb
ish_manager-0.1.8.378 app/controllers/ish_manager/user_profiles_controller.rb