Class: DraftController

Inherits:
ApplicationController show all
Defined in:
app/controllers/draft_controller.rb

Constant Summary

Constants included from PaginationHelper

PaginationHelper::DEFAULT_OPTIONS, PaginationHelper::OPTIONS

Instance Method Summary collapse

Methods included from PaginationHelper

included, #paginate, validate_options!

Instance Method Details

#destroyObject


58
59
60
61
# File 'app/controllers/draft_controller.rb', line 58

def destroy
  Draft.find(@params['id']).destroy rescue nil
  redirect_to_draft
end

#editObject


27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/controllers/draft_controller.rb', line 27

def edit
  begin
    @draft = Draft.find(@params['id'])
  rescue ActiveRecord::RecordNotFound
    redirect_to_draft
    return
  end
  
  if @request.post?
    @draft.attributes = @params['draft']
    if @draft.save
      flash['notice'] = "Draft was successfully saved."
      redirect_to_draft
    end
  end
end

#indexObject


6
7
8
9
# File 'app/controllers/draft_controller.rb', line 6

def index
  list
  render_action 'list'
end

#listObject


11
12
13
# File 'app/controllers/draft_controller.rb', line 11

def list
  @drafts = current_user.drafts.find_all(nil, 'created_at ASC')
end

#newObject


15
16
17
18
19
20
21
22
23
24
25
# File 'app/controllers/draft_controller.rb', line 15

def new
  @draft = Draft.new
  if @request.post?
    @draft.attributes = @params['draft']
    @draft.user = current_user
    if @draft.save
      flash['notice'] = "Draft was successfully saved."
      return
    end
  end
end

#postObject


44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'app/controllers/draft_controller.rb', line 44

def post
  begin 
    draft            = Draft.find(@params['id'])
    post             = current_user.posts.build
    post.subject     = draft.subject
    post.body        = draft.body
    post.save
    send_trackback(post, draft.tb_url, @app_config) unless draft.tb_url.empty?
    draft.destroy
  rescue ActiveRecord::RecordNotFound
  end
  redirect_to_draft
end