Skip to content

Commit

Permalink
Chapter 11
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonylewis committed Nov 24, 2014
1 parent b7dced9 commit 5c08f7f
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 3 deletions.
14 changes: 14 additions & 0 deletions app/controllers/text_posts_controller.rb
Expand Up @@ -15,6 +15,20 @@ def create
end
end

def edit
@text_post = current_user.text_posts.find(params[:id])
end

def update
@text_post = current_user.text_posts.find(params[:id])

if @text_post.update(text_post_params)
redirect_to post_path(@text_post), notice: "Post updated!"
else
render :edit, alert: "Error updating post."
end
end

private

def text_post_params
Expand Down
9 changes: 8 additions & 1 deletion app/views/text_posts/_text_post.html.erb
Expand Up @@ -8,6 +8,13 @@
<div class="panel-body">
<p><em>By <%= text_post.user.name %></em></p>

<%= text_post.body %>
<%= sanitize text_post.body %>
<% if text_post.user == current_user %>
<p>
<%= link_to 'Edit', edit_text_post_path(text_post),
class: "btn btn-default" %>
</p>
<% end %>
</div>
</div>
5 changes: 5 additions & 0 deletions app/views/text_posts/edit.html.erb
@@ -0,0 +1,5 @@
<div class="page-header">
<h1>Edit Text Post</h1>
</div>

<%= render 'form' %>
2 changes: 1 addition & 1 deletion app/views/users/show.html.erb
Expand Up @@ -5,7 +5,7 @@
<p class="lead"><%= @user.name %></p>

<%= link_to "Follow", follow_user_path(@user),
class: "btn btn-default" %>
method: :post, class: "btn btn-default" %>

<h2>Posts</h2>

Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Expand Up @@ -7,7 +7,7 @@
resources :sessions

get 'signup', to: 'users#new', as: 'signup'
get 'follow/:id', to: 'users#follow', as: 'follow_user'
post 'follow/:id', to: 'users#follow', as: 'follow_user'

get 'login', to: 'sessions#new', as: 'login'
get 'logout', to: 'sessions#destroy', as: 'logout'
Expand Down

0 comments on commit 5c08f7f

Please sign in to comment.