From 678e03deedae4b481ddf96a2e5bd1ba5f8a4331b Mon Sep 17 00:00:00 2001 From: nilsding Date: Mon, 29 Dec 2014 11:21:43 +0100 Subject: [PATCH] uploading profile pictures works now --- app/controllers/user_controller.rb | 9 +++++---- app/views/user/edit.html.haml | 4 +++- 2 files changed, 8 insertions(+), 5 deletions(-) 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'