Streamline profile/registration editing

This commit is contained in:
Petko Bordjukov 2015-08-15 08:01:48 +03:00
parent 2ef85a6d19
commit 2838f81327
6 changed files with 33 additions and 8 deletions

View File

@ -37,7 +37,7 @@ module Public
if current_user.personal_profile(current_conference).present? if current_user.personal_profile(current_conference).present?
redirect_to root_path redirect_to root_path
else else
redirect_to new_personal_profile_path, alert: I18n.t(:please_fill_in_your_speaker_profile) redirect_to edit_personal_profile_path, alert: I18n.t(:please_fill_in_your_speaker_profile)
end end
end end
end end

View File

@ -2,10 +2,6 @@ module Public
class PersonalProfilesController < Public::ApplicationController class PersonalProfilesController < Public::ApplicationController
before_filter :authenticate_user! before_filter :authenticate_user!
def new
@profile = current_user.build_personal_profile(current_conference)
end
def create def create
@profile = current_user.build_personal_profile(current_conference, profile_params) @profile = current_user.build_personal_profile(current_conference, profile_params)
@ -18,7 +14,7 @@ module Public
end end
def edit def edit
@profile = current_user.personal_profile(current_conference) @profile = current_user.find_or_build_personal_profile(current_conference)
end end
def update def update

View File

@ -9,8 +9,18 @@ class User < ActiveRecord::Base
has_many :workshops has_many :workshops
has_many :events has_many :events
def find_or_build_personal_profile(conference, params = {})
current_profile = personal_profile(conference)
if current_profile.present?
current_profile.assign_attributes params
current_profile
else
build_personal_profile(conference, params)
end
end
def build_personal_profile(conference, params = {}) def build_personal_profile(conference, params = {})
new_personal_profile = personal_profiles.last.dup || personal_profiles.build new_personal_profile = personal_profiles.last.try(:dup) || personal_profiles.build
new_personal_profile.conference = conference new_personal_profile.conference = conference
new_personal_profile.assign_attributes params new_personal_profile.assign_attributes params
new_personal_profile new_personal_profile

View File

@ -119,6 +119,7 @@ bg:
password: Парола password: Парола
password_confirmation: Отново паролата password_confirmation: Отново паролата
remember_me: Запомни ме remember_me: Запомни ме
language: Език
personal_profile: personal_profile:
picture: Снимка picture: Снимка
first_name: Име first_name: Име

View File

@ -17,3 +17,21 @@
.form-actions .form-actions
= f.button :submit = f.button :submit
h3.entry-title = t :login_data
= simple_form_for(current_user, wrapper: :default, as: :user, url: registration_path(:user), html: { method: :put, multipart: true }) do |f|
.form-inputs
= f.input :email, required: true
= f.input :language, collection: I18n.available_locales, required: true
- if current_user.pending_reconfirmation?
p
= t :expected_validation, email: current_user.unconfirmed_email
= f.input :password, autocomplete: "off", hint: t(:pass_update_hint1), required: false
= f.input :password_confirmation, required: false
= f.input :current_password, hint: t(:pass_update_hint2), required: true
.form-actions
= f.button :submit, t(:update)

View File

@ -17,7 +17,7 @@ nav
= link_to t(:login), new_user_session_path = link_to t(:login), new_user_session_path
- else - else
== content_tag :li, class: [('current_page_item' if controller_name == 'registrations')] do == content_tag :li, class: [('current_page_item' if controller_name == 'registrations')] do
= link_to t(:edit_speaker_profile), edit_user_registration_path = link_to t(:edit_speaker_profile), edit_personal_profile_path
li li
= link_to t(:logout), destroy_user_session_path, method: :delete = link_to t(:logout), destroy_user_session_path, method: :delete
li li