Created
June 18, 2015 08:21
-
-
Save soilforlifeforms/4a6fdb23ada494152d71 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
| <% @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> |
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 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