class PostsController

Public Instance Methods

create() click to toggle source
# File guides/code/getting_started/app/controllers/posts_controller.rb, line 31
def create
  @post = Post.new(post_params)

  if @post.save
    redirect_to action: :show, id: @post.id
  else
    render 'new'
  end
end
destroy() click to toggle source
# File guides/code/getting_started/app/controllers/posts_controller.rb, line 41
def destroy
  @post = Post.find(params[:id])
  @post.destroy

  redirect_to action: :index
end
edit() click to toggle source
# File guides/code/getting_started/app/controllers/posts_controller.rb, line 13
def edit
  @post = Post.find(params[:id])
end
index() click to toggle source
# File guides/code/getting_started/app/controllers/posts_controller.rb, line 5
def index
  @posts = Post.all
end
new() click to toggle source
# File guides/code/getting_started/app/controllers/posts_controller.rb, line 27
def new
  @post = Post.new
end
show() click to toggle source
# File guides/code/getting_started/app/controllers/posts_controller.rb, line 9
def show
  @post = Post.find(params[:id])
end
update() click to toggle source
# File guides/code/getting_started/app/controllers/posts_controller.rb, line 17
def update
  @post = Post.find(params[:id])

  if @post.update(post_params)
    redirect_to action: :show, id: @post.id
  else
    render 'edit'
  end
end

Private Instance Methods

post_params() click to toggle source
# File guides/code/getting_started/app/controllers/posts_controller.rb, line 50
def post_params
  params.require(:post).permit(:title, :text)
end