From a508f56642b110aaa91da60916943ef3c3bed89a Mon Sep 17 00:00:00 2001 From: MatsMyncke Date: Thu, 6 Nov 2014 20:07:18 +0100 Subject: [PATCH] ik kom naar de kelder --- app/controllers/users_controller.rb | 28 ++++++++++++++++++++++++ app/views/layouts/_header.html.erb | 2 +- app/views/static_pages/overview.html.erb | 2 +- app/views/users/edit.html.erb | 22 +++++++++++++++++++ 4 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 app/views/users/edit.html.erb diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 1fba4ff..bd918d8 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,4 +1,7 @@ class UsersController < ApplicationController + before_action :logged_in_user, only: [:edit, :update, :show] + + def new @user = User.new end @@ -18,10 +21,35 @@ class UsersController < ApplicationController end end + def order + @user = User.find(params[:id]) + end + + def edit + @user = User.find(params[:id]) + end + + def update + @user = User.find(params[:id]) + if @user.update_attributes(user_params) + redirect_to @user + else + render 'edit' + end + end + private def user_params params.require(:user).permit(:name, :marks) end + # Confirms a logged-in user. + def logged_in_user + unless logged_in? + flash[:danger] = "Please log in." + redirect_to login_url + end + end + end diff --git a/app/views/layouts/_header.html.erb b/app/views/layouts/_header.html.erb index 0f7168d..44f46fb 100644 --- a/app/views/layouts/_header.html.erb +++ b/app/views/layouts/_header.html.erb @@ -15,7 +15,7 @@