From 6ee6f2040501fc0b6003bf676b52f2830690adf7 Mon Sep 17 00:00:00 2001 From: Marcin Kulik Date: Wed, 23 Oct 2013 10:00:26 +0200 Subject: [PATCH] Improve the account settings page --- app/assets/stylesheets/bootstrap.css.sass | 2 +- app/assets/stylesheets/forms.css.sass | 9 ++++++ app/controllers/users_controller.rb | 10 ++++-- app/views/users/edit.html.erb | 37 ----------------------- app/views/users/edit.html.slim | 17 +++++++++++ 5 files changed, 34 insertions(+), 41 deletions(-) delete mode 100644 app/views/users/edit.html.erb create mode 100644 app/views/users/edit.html.slim diff --git a/app/assets/stylesheets/bootstrap.css.sass b/app/assets/stylesheets/bootstrap.css.sass index d4cac7e..086ba6d 100644 --- a/app/assets/stylesheets/bootstrap.css.sass +++ b/app/assets/stylesheets/bootstrap.css.sass @@ -72,7 +72,7 @@ label, input, button, select, textarea input, textarea, .uneditable-input margin-left: 0 -input[type=text], textarea, select, .uneditable-input +input[type=text], input[type=email], textarea, select, .uneditable-input width: 210px height: 18px padding: 4px diff --git a/app/assets/stylesheets/forms.css.sass b/app/assets/stylesheets/forms.css.sass index dbc0953..07256de 100644 --- a/app/assets/stylesheets/forms.css.sass +++ b/app/assets/stylesheets/forms.css.sass @@ -2,3 +2,12 @@ span.error color: red margin-left: 5px + +.simple_form + .form-inputs + div.input + margin-bottom: 10px + + .form-actions + padding: 10px 0 0 + margin: 0 diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index a8f80ed..b2e6b8e 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -37,9 +37,13 @@ class UsersController < ApplicationController end def update - current_user.update_attributes(params[:user]) - redirect_to profile_path(current_user), - :notice => 'Account settings saved.' + @user = User.find(current_user.id) + + if @user.update_attributes(params[:user]) + redirect_to profile_path(@user), notice: 'Account settings saved.' + else + render :edit, status: 422 + end end private diff --git a/app/views/users/edit.html.erb b/app/views/users/edit.html.erb deleted file mode 100644 index da51418..0000000 --- a/app/views/users/edit.html.erb +++ /dev/null @@ -1,37 +0,0 @@ -
-
- <%= form_for @user, :html => { :class => 'form-horizontal' } do |f| %> -
- Account settings - -
- <%= f.label :nickname, 'Username', :class => 'control-label' %> -
- <%= f.text_field :nickname, :class => 'text_field' %> -
-
- -
- <%= f.label :name, 'Real name', :class => 'control-label' %> -
- <%= f.text_field :name, :class => 'text_field' %> -
-
- -
- <%= f.label :email, :class => 'control-label' %> -
- <%= f.text_field :email, :class => 'text_field' %> -
-
- -
- <%= f.submit 'Save', :class => 'btn btn-primary' %> - <%= link_to 'Cancel', profile_path(@user), :class => 'btn' %> -
-
- <% end %> - -
-
-
diff --git a/app/views/users/edit.html.slim b/app/views/users/edit.html.slim new file mode 100644 index 0000000..292d340 --- /dev/null +++ b/app/views/users/edit.html.slim @@ -0,0 +1,17 @@ +section.supplimental + .wrapper + h1 Your account + + = simple_form_for(@user) do |f| + = f.error_notification + + .form-inputs + = f.input :nickname, label: 'Username' + = f.input :email + = f.input :name, label: 'Real name' + + .form-actions + = f.button :submit, 'Save' + = link_to 'Cancel', profile_path(current_user), class: 'btn' + + .vertical-expander