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