Class: Storytime::Dashboard::BlogsController

Inherits:
PostsController show all
Defined in:
app/controllers/storytime/dashboard/blogs_controller.rb

Instance Method Summary collapse

Methods inherited from PostsController

#show

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



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/controllers/storytime/dashboard/blogs_controller.rb', line 32

def create
  @blog = current_post_type.new(post_params)
  @blog.user = current_user
  @blog.draft_user_id = current_user.id
  @blog.published_at = Time.now.utc
  authorize @blog

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

#destroyObject



48
49
50
51
52
53
54
55
56
# File 'app/controllers/storytime/dashboard/blogs_controller.rb', line 48

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

#editObject



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

def edit
  authorize @post
  @blog = @post
  respond_with @blog
end

#newObject



6
7
8
9
10
11
# File 'app/controllers/storytime/dashboard/blogs_controller.rb', line 6

def new
  @blog = current_post_type.new
  @blog.user = current_user
  authorize @blog
  respond_with @blog
end

#updateObject



19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/controllers/storytime/dashboard/blogs_controller.rb', line 19

def update
  authorize @post
  @blog = @post

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