diff --git a/app/models/user.rb b/app/models/user.rb index b790a39..1124038 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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 } diff --git a/lib/open_fest/app/controllers/open_fest/personal_profiles_controller.rb b/lib/open_fest/app/controllers/open_fest/personal_profiles_controller.rb new file mode 100644 index 0000000..cd29086 --- /dev/null +++ b/lib/open_fest/app/controllers/open_fest/personal_profiles_controller.rb @@ -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 diff --git a/lib/open_fest/app/views/open_fest/personal_profiles/_form.slim b/lib/open_fest/app/views/open_fest/personal_profiles/_form.slim new file mode 100644 index 0000000..14d49d3 --- /dev/null +++ b/lib/open_fest/app/views/open_fest/personal_profiles/_form.slim @@ -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 diff --git a/lib/open_fest/app/views/open_fest/personal_profiles/edit.slim b/lib/open_fest/app/views/open_fest/personal_profiles/edit.slim new file mode 100644 index 0000000..d48bae0 --- /dev/null +++ b/lib/open_fest/app/views/open_fest/personal_profiles/edit.slim @@ -0,0 +1,5 @@ +- content_for(:title) { ":: #{t :personal_profile}" } + +h2.entry-title = t :personal_profile + += render 'form' diff --git a/lib/open_fest/app/views/open_fest/personal_profiles/new.slim b/lib/open_fest/app/views/open_fest/personal_profiles/new.slim new file mode 100644 index 0000000..d48bae0 --- /dev/null +++ b/lib/open_fest/app/views/open_fest/personal_profiles/new.slim @@ -0,0 +1,5 @@ +- content_for(:title) { ":: #{t :personal_profile}" } + +h2.entry-title = t :personal_profile + += render 'form' diff --git a/lib/open_fest/app/views/open_fest/users/registrations/edit.slim b/lib/open_fest/app/views/open_fest/users/registrations/edit.slim index 54fd8cb..e474613 100644 --- a/lib/open_fest/app/views/open_fest/users/registrations/edit.slim +++ b/lib/open_fest/app/views/open_fest/users/registrations/edit.slim @@ -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 diff --git a/lib/open_fest/config/routes.rb b/lib/open_fest/config/routes.rb index 45e1f8c..de7313c 100644 --- a/lib/open_fest/config/routes.rb +++ b/lib/open_fest/config/routes.rb @@ -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