diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb index cc560d54..3cb5eee1 100644 --- a/app/controllers/user_controller.rb +++ b/app/controllers/user_controller.rb @@ -1,4 +1,6 @@ class UserController < ApplicationController + before_filter :authenticate_user!, only: %w(edit update) + def show @user = User.where('LOWER(screen_name) = ?', params[:username].downcase).first! @answers = @user.answers.reverse_order.paginate(page: params[:page]) @@ -9,14 +11,13 @@ class UserController < ApplicationController end def edit - authenticate_user! end def update - authenticate_user! - user_attributes = params.require(:user).permit(:display_name, :motivation_header, :website, :location, :bio) + user_attributes = params.require(:user).permit(:display_name, :profile_picture, :motivation_header, :website, + :location, :bio) unless current_user.update_attributes(user_attributes) - flash[:error] = 'fork it' + flash[:error] = 'An error occurred. ;_;' end redirect_to edit_user_profile_path end diff --git a/app/views/user/edit.html.haml b/app/views/user/edit.html.haml index a39e380f..b9ffbbc0 100644 --- a/app/views/user/edit.html.haml +++ b/app/views/user/edit.html.haml @@ -4,10 +4,12 @@ = render 'layouts/messages' .panel.panel-default .panel-body - = bootstrap_form_for(current_user, url: {action: "edit"}, method: "patch") do |f| + = bootstrap_form_for(current_user, url: {action: "edit"}, :html => { :multipart => true }, method: "patch") do |f| = f.text_field :display_name, label: "Your name" + = f.file_field :profile_picture + = f.text_field :motivation_header, label: "Motivation header", placeholder: 'Ask me anything!' = f.text_field :website, label: "Website", placeholder: 'http://bad-dragon.com'