uploading profile pictures works now

This commit is contained in:
nilsding 2014-12-29 11:21:43 +01:00
parent 501f039e7f
commit 678e03deed
2 changed files with 8 additions and 5 deletions

View File

@ -1,4 +1,6 @@
class UserController < ApplicationController class UserController < ApplicationController
before_filter :authenticate_user!, only: %w(edit update)
def show def show
@user = User.where('LOWER(screen_name) = ?', params[:username].downcase).first! @user = User.where('LOWER(screen_name) = ?', params[:username].downcase).first!
@answers = @user.answers.reverse_order.paginate(page: params[:page]) @answers = @user.answers.reverse_order.paginate(page: params[:page])
@ -9,14 +11,13 @@ class UserController < ApplicationController
end end
def edit def edit
authenticate_user!
end end
def update def update
authenticate_user! user_attributes = params.require(:user).permit(:display_name, :profile_picture, :motivation_header, :website,
user_attributes = params.require(:user).permit(:display_name, :motivation_header, :website, :location, :bio) :location, :bio)
unless current_user.update_attributes(user_attributes) unless current_user.update_attributes(user_attributes)
flash[:error] = 'fork it' flash[:error] = 'An error occurred. ;_;'
end end
redirect_to edit_user_profile_path redirect_to edit_user_profile_path
end end

View File

@ -4,10 +4,12 @@
= render 'layouts/messages' = render 'layouts/messages'
.panel.panel-default .panel.panel-default
.panel-body .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.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 :motivation_header, label: "Motivation header", placeholder: 'Ask me anything!'
= f.text_field :website, label: "Website", placeholder: 'http://bad-dragon.com' = f.text_field :website, label: "Website", placeholder: 'http://bad-dragon.com'