-
-
Save richardsondx/bae9d852821d57bd04d2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<li> | |
<%= truncate(experience.content, length: 200) { button_to "Continue", { action: "#" }, method: :get } %> | |
</li> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%= provide(:title, "All users") %> | |
<div class="wrapper"> | |
<div class="listed"> | |
<p>Users Directory</p> | |
<%= will_paginate %> | |
<ul> | |
<% @users.each do |user| %> | |
<%= render @users %> | |
<% end %> | |
</ul> | |
<%= will_paginate %> | |
</div> | |
</div> | |
# _user.html.erb: | |
<li> | |
<%= link_to user.name, user %> | |
<% if current_user.admin? && !current_user?(user) %> | |
<%= link_to("delete", user, method: "delete", data: { confirm: "Are you sure?"}, class: "small-button") %> | |
<% end %> | |
</li> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.pagination a, .pagination span, .pagination em { | |
padding: 0.2em 0.5em; | |
display: block; | |
float: left; | |
margin-right: 1px; | |
} | |
.pagination .disabled { | |
color: #999999; | |
border: 1px solid #dddddd; | |
} | |
.pagination .current { | |
font-style: normal; | |
font-weight: bold; | |
background: rgba(255, 0, 0, 0.8); | |
color: black; | |
border: 1px solid rgba(255, 0, 0, 0.8); | |
} | |
.pagination a { | |
text-decoration: none; | |
color: #999999; | |
border: 1px solid #dddddd; | |
} | |
.pagination a:hover, .pagination a:focus { | |
color: rgba(255, 0, 0, 0.8); | |
border-color: rgba(255, 0, 0, 0.2); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%= provide(:title, 'Stories') %> | |
<div class="wrapper"> | |
<div class="listed"> | |
<p>Stories</p> | |
<%= will_paginate %> | |
<ul> | |
<%= render @experiences %> #i'm following what Hartl did here | |
</ul> | |
<%= will_paginate %> | |
</div> | |
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def index | |
@experiences = Experience.paginate(page: params[:page], per_page: 10) | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class UsersController < ApplicationController | |
before_action :signed_in_user, only: [:index, :edit, :update, :destroy] | |
before_action :correct_user, only: [:edit, :update] | |
before_action :admin_user, only: [:destroy] | |
def index | |
@users = User.paginate(page: params[:page], per_page: 20) | |
end | |
def show | |
@user = User.find(params[:id]) | |
end | |
def new | |
@user = User.new | |
end | |
def create | |
@user = User.new(user_params) | |
if @user.save | |
redirect_to @user | |
flash[:success] = "Welcome! Happy venting!" | |
else | |
render 'new' | |
end | |
end | |
def edit | |
end | |
def update | |
@user = User.find(params[:id]) | |
if @user.update_attributes(user_params) | |
flash[:success] = "Successfully updated" | |
redirect_to @user | |
else | |
render 'edit' | |
end | |
end | |
def destroy | |
User.find(params[:id]).destroy | |
flash[:success] = "User deleted." | |
redirect_to users_url | |
end | |
private | |
def user_params | |
params.require(:user).permit(:name, :email, :password, :password_confirmation) #admin is not an option for security reasons | |
end | |
def signed_in_user | |
unless signed_in? | |
store_location | |
redirect_to signin_url, notice: "Please sign in." #flash[:notice] | |
end | |
end | |
def correct_user | |
@user = User.find(params[:id]) | |
redirect_to(root_url) unless current_user?(@user) | |
end | |
end | |
def admin_user | |
redirect_to(root_url) if !current_user.admin? | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment