Allow to edit address from user profile
This commit is contained in:
parent
7ac3f54709
commit
56f6efa590
3 changed files with 24 additions and 4 deletions
|
@ -15,7 +15,8 @@ class HomeController < ApplicationController
|
|||
end
|
||||
|
||||
def update_profile
|
||||
if @current_user.update_attributes(params[:user])
|
||||
if @current_user.update_attributes(user_params)
|
||||
@current_user.ordergroup.update_attributes(ordergroup_params) if ordergroup_params
|
||||
session[:locale] = @current_user.locale
|
||||
redirect_to my_profile_url, notice: I18n.t('home.changes_saved')
|
||||
else
|
||||
|
@ -62,4 +63,20 @@ class HomeController < ApplicationController
|
|||
redirect_to my_profile_path
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def user_params
|
||||
params
|
||||
.require(:user)
|
||||
.permit(:first_name, :last_name, :email, :phone,
|
||||
:password, :password_confirmation).merge(params[:user].slice(:settings_attributes))
|
||||
end
|
||||
|
||||
def ordergroup_params
|
||||
params
|
||||
.require(:user)
|
||||
.require(:ordergroup)
|
||||
.permit(:contact_address)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
= h(t('.user.title', user: show_user))
|
||||
%small= t '.user.since', when: distance_of_time_in_words(Time.now, @current_user.created_on)
|
||||
= simple_form_for(@current_user, :url => update_profile_path) do |f|
|
||||
= render :partial => 'shared/user_form_fields', :locals => {:f => f, :password_autocomplete => 'store-only'}
|
||||
= render :partial => 'shared/user_form_fields', :locals => {:f => f, :password_autocomplete => 'store-only', with_address: true}
|
||||
.form-actions
|
||||
= submit_tag t('ui.save'), class: 'btn'
|
||||
.span5
|
||||
|
|
|
@ -6,12 +6,15 @@
|
|||
-# You can control password autocompletion by passing `password_autocomplete` to this partial.
|
||||
-# Possible values: undefined/nil, true, false, 'store-only'
|
||||
-# see also https://github.com/foodcoops/foodsoft/wiki/Form-autocompletion
|
||||
- password_autocomplete = nil unless defined?(:password_autocomplete)
|
||||
- password_html = autocomplete_flag_to_password_html(password_autocomplete)
|
||||
- password_html = autocomplete_flag_to_password_html(local_assigns[:password_autocomplete])
|
||||
= f.input :password, :required => f.object.new_record?, input_html: password_html
|
||||
= f.input :password_confirmation, :required => f.object.new_record?, input_html: password_html
|
||||
= f.input :phone
|
||||
|
||||
- if local_assigns[:with_address] && (f.object.ordergroup || f.object.new_record?)
|
||||
= f.fields_for [:ordergroup, f.object.ordergroup || Ordergroup.new] do |ogf|
|
||||
= ogf.input :contact_address, label: t('activerecord.attributes.ordergroup.contact_address'), required: false
|
||||
|
||||
= f.simple_fields_for :settings_attributes do |s|
|
||||
= s.simple_fields_for :profile, defaults: { inline_label: true } do |profile|
|
||||
= profile.input 'language', as: :select, collection: available_locales, required: false, selected: f.object.settings.profile['language']
|
||||
|
|
Loading…
Reference in a new issue