LoginSignup
0
0

More than 3 years have passed since last update.

posts_controller.rb

Posted at

class PostsController < ApplicationController
def index
# Post.allにorderメソッドを用いて、新しい投稿が上から順に表示されるようにしてください
@posts = Post.all.order(created_at: :desc)
end

def show
@post = Post.find_by(id: params[:id])
end

def new
end

def create
@post = Post.new(content: params[:content])
@post.save
redirect_to("/posts/index")
end
end

//降順にデータベースに投稿された内容を表示する

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0