ik kom naar de kelder

This commit is contained in:
MatsMyncke 2014-11-06 20:07:18 +01:00
parent af6f2668e6
commit a508f56642
4 changed files with 52 additions and 2 deletions

View file

@ -1,4 +1,7 @@
class UsersController < ApplicationController class UsersController < ApplicationController
before_action :logged_in_user, only: [:edit, :update, :show]
def new def new
@user = User.new @user = User.new
end end
@ -18,10 +21,35 @@ class UsersController < ApplicationController
end end
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 private
def user_params def user_params
params.require(:user).permit(:name, :marks) params.require(:user).permit(:name, :marks)
end 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 end

View file

@ -15,7 +15,7 @@
</a> </a>
<ul class="dropdown-menu"> <ul class="dropdown-menu">
<li><%= link_to "Profile", current_user %></li> <li><%= link_to "Profile", current_user %></li>
<li><%= link_to "Settings", '#' %></li> <li><%= link_to "Settings", edit_user_path(current_user) %></li>
<li class="divider"></li> <li class="divider"></li>
<li> <li>
<%= link_to "Log out", logout_path, method: "delete" %> <%= link_to "Log out", logout_path, method: "delete" %>

View file

@ -23,4 +23,4 @@
window.document.location = $(this).attr("href"); window.document.location = $(this).attr("href");
}); });
}); });
</script> </script>

View file

@ -0,0 +1,22 @@
<% provide(:title, "Edit user") %>
<h1>Update your profile</h1>
<div class="row">
<div class="col-md-6 col-md-offset-3">
<%= form_for(@user) do |f| %>
<%= f.label :name %>
<%= f.text_field :name, class: 'form-control' %>
<%= f.label :marks %>
<%= f.number_field :marks, class: 'form-control' %>
<%= f.submit "Save changes", class: "btn btn-primary" %>
<% end %>
</div>
</div>