Skip to content

Commit

Permalink
completed exercises
Browse files Browse the repository at this point in the history
  • Loading branch information
MrEdwardo committed Sep 5, 2011
1 parent 7e815d9 commit 6612f98
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 40 deletions.
2 changes: 1 addition & 1 deletion I_AM_HERE.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
10.1.2 Enabling edits
10.6 exercises
5 changes: 5 additions & 0 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ class UsersController < ApplicationController
before_filter :authenticate, :only => [:index, :edit, :update]
before_filter :correct_user, :only => [:edit, :update]
before_filter :admin_user, :only => :destroy
before_filter :signed_out_user, :only => [:create, :new]

def index
@title = "All users"
Expand Down Expand Up @@ -55,6 +56,10 @@ def update

private

def signed_out_user
redirect_to(root_path) unless !current_user.signed_in?
end

def admin_user
redirect_to(root_path) unless current_user.admin?
end
Expand Down
4 changes: 2 additions & 2 deletions app/views/layouts/_header.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
<%= link_to logo, root_path %>
<nav class="round">
<ul>
<li><%= link_to "Home", 'root_path' %></li>
<li><%= link_to "Home", root_path %></li>

<% if signed_in? %>
<li><%= link_to "Users", users_path %></li>
<li><%= link_to "Profile", current_user %></li>
<li><%= link_to "Settings", edit_user_path(current_user) %></li>
<% end %>

<li><%= link_to "Help", 'help_path' %></li>
<li><%= link_to "Help", help_path %></li>

<% if signed_in? %>
<li><%= link_to "Sign out", signout_path, :method => :delete %></li>
Expand Down
17 changes: 17 additions & 0 deletions app/views/users/_fields.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<%= render 'shared/error_messages', :object => f.object %>
<div class="field">
<%= f.label :name %><br />
<%= f.text_field :name %>
</div>
<div class="field">
<%= f.label :email %><br />
<%= f.text_field :email %>
</div>
<div class="field">
<%= f.label :password %><br />
<%= f.password_field :password %>
</div>
<div class="field">
<%= f.label :password_confirmation, "Confirmation" %><br />
<%= f.password_field :password_confirmation %>
</div>
7 changes: 7 additions & 0 deletions app/views/users/_user.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<li>
<%= gravatar_for user, :size => 30 %>
<%= link_to user.name, user %>
<% if current_user.admin? %>
<%= link_to "delete", user, :method => :delete, :confirm => "You sure?", :title => "Delete #{user.name}" %>
<% end %>
</li>
22 changes: 3 additions & 19 deletions app/views/users/edit.html.erb
Original file line number Diff line number Diff line change
@@ -1,29 +1,13 @@
<h1>Edit user</h1>

<%= form_for(@user) do |f| %>
<%= render 'shared/error_messages', :object => f.object %>
<div class="field">
<%= f.label :name %><br />
<%= f.text_field :name %>
</div>
<div class="field">
<%= f.label :email %><br />
<%= f.text_field :email %>
</div>
<div class="field">
<%= f.label :password %><br />
<%= f.password_field :password %>
</div>
<div class="field">
<%= f.label :password_confirmation, "Confirmation" %><br />
<%= f.password_field :password_confirmation %>
</div>
<%= render 'fields', :f => f %>
<div class="actions">
<%= f.submit "Update" %>
<%= f.submit "Save" %>
</div>
<% end %>

<div>
<%= gravatar_for @user %>
<a href="http://gravatar.com/emails">change</a>
<%= link_to 'change', "http://gravatar.com/emails", :target => '_blank' %>
</div>
20 changes: 2 additions & 18 deletions app/views/users/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,24 +1,8 @@
<h1>Sign up</h1>

<%= form_for(@user) do |f| %>
<%= render 'shared/error_messages', :object => f.object %>
<div class="field">
<%= f.label :name %><br />
<%= f.text_field :name %>
</div>
<div class="field">
<%= f.label :email %><br />
<%= f.text_field :email %>
</div>
<div class="field">
<%= f.label :password %><br />
<%= f.password_field :password %>
</div>
<div class="field">
<%= f.label :password_confirmation, "Confirmation" %><br />
<%= f.password_field :password_confirmation %>
</div>
<%= render 'fields', :f => f %>
<div class="actions">
<%= f.submit "Sign up" %>
</div>
<% end %>
<% end %>

0 comments on commit 6612f98

Please sign in to comment.