Skip to content

Instantly share code, notes, and snippets.

@soilforlifeforms
Created June 18, 2015 08:21
Show Gist options
  • Select an option

  • Save soilforlifeforms/4a6fdb23ada494152d71 to your computer and use it in GitHub Desktop.

Select an option

Save soilforlifeforms/4a6fdb23ada494152d71 to your computer and use it in GitHub Desktop.
<% @posts.each do |post| %>
<li>
#<%= link_to post.title, (post) %>
<%= link_to 'show', post_path(post) %>
</li> <p> Comments (<%= post.comments.size %>) </p>
<%= truncate post.body, length: 300 %>
<% end %>
</div>
</div>
class PostsController < ApplicationController
include PostsHelper
before_action :authenticate_user!
def index
@posts = Post.all
#@post = Post.find(params[:id])
end
def new
@post = Post.new
end
def show
@post = Post.find(params[:id])
@comment = Comment.new
@comment.post_id = @post.id
#redirect_to post_path(@comment.post)
# @coment.user = current_user.id
end
def create
@post = Post.new(post_params)
@post.save
redirect_to post_path(@post)
end
def edit
@post = Post.find(params[:id])
end
def update
@post = Post.find(params[:id])
@post.update(post_params)
flash.notice = "Post '#{@post.title}' Updated!"
redirect_to post_path(@post)
end
def destroy
@post = Post.find(params[:id])
@post.destroy
redirect_to posts_path
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment