Class: Storytime::Dashboard::SnippetsController

Inherits:
Storytime::DashboardController show all
Defined in:
app/controllers/storytime/dashboard/snippets_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#authenticate_user!, #current_user, #setup, #user_signed_in?

Methods included from Concerns::CurrentSite

#current_storytime_site

Methods included from Concerns::ControllerContentFor

#content_for, #content_for?, #view_context

Instance Method Details

#createObject



29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/controllers/storytime/dashboard/snippets_controller.rb', line 29

def create
  @snippet = Storytime::Snippet.new(snippet_params)
  authorize @snippet

  respond_with @snippet do |format|
    if @snippet.save
      format.json { render :index }
    else
      format.json { render :new, status: :unprocessable_entity }
    end
  end
end

#destroyObject



54
55
56
57
58
59
60
61
62
# File 'app/controllers/storytime/dashboard/snippets_controller.rb', line 54

def destroy
  authorize @snippet
  @snippet.destroy
  flash[:notice] = I18n.t('flash.snippets.destroy.success') unless request.xhr?
  
  respond_with [:dashboard, @snippet] do |format|
    format.html{ redirect_to url_for([:dashboard, Storytime::Snippet]) }
  end
end

#editObject



24
25
26
27
# File 'app/controllers/storytime/dashboard/snippets_controller.rb', line 24

def edit
  authorize @snippet
  respond_with @snippet
end

#indexObject



13
14
15
16
# File 'app/controllers/storytime/dashboard/snippets_controller.rb', line 13

def index
  authorize @snippets
  respond_with @snippets
end

#newObject



18
19
20
21
22
# File 'app/controllers/storytime/dashboard/snippets_controller.rb', line 18

def new
  @snippet = Storytime::Snippet.new
  authorize @snippet
  respond_with @snippet
end

#updateObject



42
43
44
45
46
47
48
49
50
51
52
# File 'app/controllers/storytime/dashboard/snippets_controller.rb', line 42

def update
  authorize @snippet

  respond_with @snippet do |format|
    if @snippet.update(snippet_params)
      format.json { render :index }
    else
      format.json { render :edit, status: :unprocessable_entity }
    end
  end
end