Skip to content

Instantly share code, notes, and snippets.

@kaoussi
Last active March 6, 2018 18:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kaoussi/adcccf90099d3e959671bfaab0e4214c to your computer and use it in GitHub Desktop.
Save kaoussi/adcccf90099d3e959671bfaab0e4214c to your computer and use it in GitHub Desktop.
class ProfilesController < ApplicationController
layout "layout_2"
before_action :authenticate_user!
before_action :set_profile, only: [:show, :edit, :update, :destroy]
def new
@profile = current_user.profile.build
end
def create
@profile = current_user.profile.build(profile_params)
respond_to do |format|
if @profile.save
format.html { redirect_to @profile, notice: 'Success' }
format.json { render :show, status: :created, location: @profile }
else
format.html { render :new }
format.json { render json: @profile.errors, status: :unprocessable_entity }
end
end
end
def edit
end
def update
@profile = current_user.profile
if @profile.update_attributes(profile_params)
flash[:success] = "Succés"
redirect_to user_path(id: params[:user_id] )
else
flash[:error] = "Veuillez entrez des informations valides"
render action: :edit
end
end
def show
@currentUser = current_user.id
end
def destroy
end
private
def set_profile
@profile = current_user.profile
end
def profile_params
params.require(:profile).permit(:first_name, :last_name, :occupation, :birth_year, :phone_number, :city, :description, :niveau, :speciality, :formation_date, :formation_date_end, :addresse)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment