From fb48c6d995f3084f3e6ddf864d298ae786a32d59 Mon Sep 17 00:00:00 2001 From: nilsding Date: Tue, 11 Nov 2014 20:20:00 +0100 Subject: [PATCH] finally, setting the display_name works. --- app/controllers/user_controller.rb | 7 ++++--- app/models/user.rb | 4 +++- app/views/user/edit.html.haml | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb index ae5222f3..e9e8a3e3 100644 --- a/app/controllers/user_controller.rb +++ b/app/controllers/user_controller.rb @@ -9,9 +9,10 @@ class UserController < ApplicationController def update authenticate_user! - params.require(:display_name) - current_user.display_name = params[:display_name] - current_user.save! + user_attributes = params.require(:user).permit(:display_name) + unless current_user.update_attributes(user_attributes) + flash[:error] = "fork it" + end redirect_to edit_user_profile_path end end diff --git a/app/models/user.rb b/app/models/user.rb index 83b76394..9cd79bec 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -15,7 +15,9 @@ class User < ActiveRecord::Base SCREEN_NAME_REGEX = /\A[a-zA-Z0-9_]{1,16}\z/ validates :screen_name, presence: true, format: { with: SCREEN_NAME_REGEX }, uniqueness: { case_sensitive: false } - + + + def login=(login) @login = login end diff --git a/app/views/user/edit.html.haml b/app/views/user/edit.html.haml index d15a1ab4..00ec8454 100644 --- a/app/views/user/edit.html.haml +++ b/app/views/user/edit.html.haml @@ -3,7 +3,7 @@ .col-md-9.col-xs-12.col-sm-9 .panel.panel-default .panel-body - = bootstrap_form_for(update_user_profile_path, method: "patch") do |f| + = bootstrap_form_for(:user, method: "patch") do |f| = f.text_field :display_name, label: "Your name"