Skip to content

Commit

Permalink
Fix update user. Fixes #601
Browse files Browse the repository at this point in the history
  • Loading branch information
barkinsv committed May 17, 2016
1 parent 8ac8f62 commit bca2704
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
4 changes: 2 additions & 2 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ def workplan

def update
@user = User.where("company_id = ?", current_user.company_id).find(params[:id])

if @user.update_attributes(user_update_params)
flash[:success] = t('flash.notice.model_updated', model: User.model_name.human)
redirect_to edit_user_path(@user)
Expand Down Expand Up @@ -230,7 +229,8 @@ def user_create_params
def user_update_params
params.require(:user).permit :name, :username, :password, :customer_id, :avatar, :locale, :time_zone, :receive_notifications,
:receive_own_notifications, :auto_add_to_customer_tasks, :active, :comment_private_by_default, :time_format, :date_format,
:option_tracktime, :option_avatars, :set_custom_attribute_values => [:custom_attribute_id, :value, :choice_id]
:option_tracktime, :option_avatars, :set_custom_attribute_values => [:custom_attribute_id, :value, :choice_id],
customer_attributes: [:id, :name]
end

def user_access_params
Expand Down
2 changes: 1 addition & 1 deletion app/models/custom_attribute_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def set_custom_attribute_values=(params)
cav ||= custom_attribute_values.build(values)

if !new_record?
cav.save
cav.update(value: values[:value])
end
updated << cav
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class User < ActiveRecord::Base
attachment.instance.company_id
end

accepts_nested_attributes_for :work_plan
accepts_nested_attributes_for :work_plan, :customer

include PreferenceMethods

Expand Down
6 changes: 4 additions & 2 deletions app/views/users/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@
<div class="control-group">
<label for="user_customer_id"><%= t("users.company") %></label>
<div class="controls">
<%= hidden_field_tag("user[customer_id]", @user.customer_id, :id => "user_customer_id", :class => "auto_complete_id") %>
<%= text_field :customer, :name, {:id=>"user_customer_name", :value => @user.customer.try(:name)} %>
<%= fields_for("user[customer_attributes]", @user.customer) do |fields|%>
<%= fields.hidden_field :id, class: "auto_complete_id" %>
<%= fields.text_field :name %>
<% end %>
<a href="<%= @user.customer.nil? ? "#" : "/customers/#{@user.customer.id}/edit" %>" id="user_customer_link"><i class="icon-share" title=<%= t("users.goto_company") %>></i></a>
</div>
</div>
Expand Down

0 comments on commit bca2704

Please sign in to comment.