Skip to content

Commit

Permalink
fix form errors and notice when nothing changed
Browse files Browse the repository at this point in the history
  • Loading branch information
Felix Van der Jeugt committed Feb 5, 2016
1 parent 670b176 commit e72e76e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
9 changes: 6 additions & 3 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@ def show
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
Expand Down
3 changes: 1 addition & 2 deletions app/views/users/_sidebar.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"

0 comments on commit e72e76e

Please sign in to comment.