Create or update profile
This commit is contained in:
parent
a75def4b95
commit
08290d1770
|
@ -8,7 +8,15 @@ class User < ActiveRecord::Base
|
|||
has_many :lectures
|
||||
has_many :workshops
|
||||
has_many :events
|
||||
has_one :personal_profile, Proc.new { |user, conference| user.personal_profiles }
|
||||
|
||||
# TODO (2015-08-05) Copy previous profile
|
||||
def build_personal_profile(conference, params)
|
||||
personal_profiles.build({conference_id: conference.id}.merge(params))
|
||||
end
|
||||
|
||||
def personal_profile(conference)
|
||||
personal_profiles.find_by(conference_id: conference.id)
|
||||
end
|
||||
|
||||
default_scope { order id: :desc }
|
||||
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
module OpenFest
|
||||
class PersonalProfilesController < ApplicationController
|
||||
def new
|
||||
@profile = current_user.build_personal_profile(current_conference)
|
||||
end
|
||||
|
||||
def create
|
||||
@profile = current_user.build_personal_profile(current_conference, profile_params)
|
||||
|
||||
if @profile.save
|
||||
flash[:notice] = t('profile.successfully_created')
|
||||
redirect_to root_path
|
||||
else
|
||||
render action: :new
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
@profile = current_user.personal_profile(current_conference)
|
||||
end
|
||||
|
||||
def update
|
||||
@profile = current_user.personal_profile(current_conference)
|
||||
|
||||
if @profile.update_attributes(profile_params)
|
||||
flash[:notice] = t('profile.successfully_updated')
|
||||
redirect_to root_path
|
||||
else
|
||||
render action: 'edit'
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def profile_params
|
||||
params.require(:personal_profile).permit(
|
||||
:picture, :picture_cache, :first_name, :last_name, :public_email,
|
||||
:organisation, :github, :twitter, :mobile_phone, :biography
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,19 @@
|
|||
= simple_form_for @profile, wrapper: :default, url: personal_profile_path do |f|
|
||||
= f.error_notification
|
||||
|
||||
.form-inputs
|
||||
= image_tag(@profile.picture.medium.url) if @profile.picture?
|
||||
= f.input :picture, as: :file, required: true
|
||||
= f.hidden_field :picture_cache
|
||||
|
||||
= f.input :first_name, autofocus: true
|
||||
= f.input :last_name
|
||||
= f.input :public_email
|
||||
= f.input :organisation
|
||||
= f.input :github
|
||||
= f.input :twitter
|
||||
= f.input :mobile_phone
|
||||
= f.input :biography
|
||||
|
||||
.form-actions
|
||||
= f.button :submit
|
|
@ -0,0 +1,5 @@
|
|||
- content_for(:title) { ":: #{t :personal_profile}" }
|
||||
|
||||
h2.entry-title = t :personal_profile
|
||||
|
||||
= render 'form'
|
|
@ -0,0 +1,5 @@
|
|||
- content_for(:title) { ":: #{t :personal_profile}" }
|
||||
|
||||
h2.entry-title = t :personal_profile
|
||||
|
||||
= render 'form'
|
|
@ -1,6 +1,13 @@
|
|||
- content_for(:title) { t :edit_speaker_profile }
|
||||
|
||||
= simple_form_for(resource, wrapper: :default, as: :user, url: user_registration_path, html: { method: :put, multipart: true }) do |f|
|
||||
.form_inputs
|
||||
h2
|
||||
- if current_user.personal_profile(current_conference).present?
|
||||
= link_to t(:personal_profile), edit_personal_profile_path
|
||||
- else
|
||||
= link_to t(:personal_profile), new_personal_profile_path
|
||||
|
||||
.form-inputs
|
||||
h3.entry-title = t :login_data
|
||||
= f.input :email, required: true
|
||||
|
|
|
@ -4,4 +4,6 @@ OpenFest::Engine.routes.draw do
|
|||
root to: 'welcome#index'
|
||||
|
||||
devise_for :users, module: 'open_fest/users'
|
||||
|
||||
resource :personal_profile, path: 'profile'
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue