Last active
March 6, 2018 18:25
-
-
Save kaoussi/adcccf90099d3e959671bfaab0e4214c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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