aboutsummaryrefslogtreecommitdiffstats
path: root/app/controllers/snippets_controller.rb
blob: 7d6f1b362924006efe6f25372480e8f9e4da27b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
class SnippetsController < ApplicationController
  before_action :set_snippet, only: [:show]

  # GET /snippets
  # TODO
  # def index
  #   @snippets = Snippet.all
  # end

  # GET /1234
  def show
  end

  # GET /
  def new
    @snippet = Snippet.new
  end

  # GET /snippets/1/edit
  # TODO
  # def edit
  # end

  # POST /create
  def create
    @snippet = Snippet.new(snippet_params)

    if @snippet.save
      redirect_to @snippet, notice: "Snippet was successfully created."
    else
      render :new
    end
  end

  # PATCH/PUT /snippets/1
  # TODO
  # def update
  #   if @snippet.update(snippet_params)
  #     redirect_to @snippet, notice: "Snippet was successfully updated."
  #   else
  #     render :edit
  #   end
  # end

  # DELETE /snippets/1
  # TODO
  # def destroy
  #   @snippet.destroy
  #   redirect_to snippets_url, notice: "Snippet was successfully destroyed."
  # end

  private
  # Use callbacks to share common setup or constraints between actions.
  def set_snippet
    @snippet = Snippet.find(params[:id])
  end

  # Only allow a trusted parameter "white list" through.
  def snippet_params
    params.require(:snippet).permit(:title, :code)
  end
end