fix form errors and notice when nothing changed

This commit is contained in:
Felix Van der Jeugt 2016-02-05 09:16:02 +01:00
parent 670b17622d
commit e72e76e9a3
2 changed files with 7 additions and 5 deletions

View file

@ -6,14 +6,17 @@ class UsersController < ApplicationController
end
def update
if @user.update_attributes(user_params)
if user_params.empty?
flash[:notice] = "Nothing happened."
redirect_to @user
elsif @user.update_attributes(user_params)
flash[:success] = "Successfully updated!"
redirect_to @user
else
flash[:error] = "Update failed!"
# TODO form errors?
@user.reload
render 'show'
end
redirect_to @user
end
def edit_dagschotel

View file

@ -14,6 +14,7 @@
%span.badge= @user.products_group_by_id.map(&:count).sum
- if can? :create, @user.orders.build
%li.list-group-item= link_to "Place new order", new_user_order_path(@user), class: "btn btn-default btn-block"
= render 'errors', object: @user
- if can? :edit, @user
%ul.list-group
%li.list-group-item.text-muted
@ -27,12 +28,10 @@
%p Orders can be placed on koelkast for every public account. Private accounts can only order products by logging in here.
// = link_to "Go #{if @user.private then "public" else "private" end}", toggle_privacy_user_path(@user), class: "btn btn-default btn-block"
= f_form_for @user do |f|
= f.error_messages
.hidden
= f.check_box :private, checked: !@user.private
= f.submit "Go #{@user.private ? "public" : "private"}", class: "btn btn-default btn-block"
%li.list-group-item.text-muted
= f_form_for @user do |f|
= f.error_messages
= f.file_field :avatar
= f.submit "Change avatar", class: "btn btn-default btn-block"