Class: Homeland::Note::NotesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/homeland/note/notes_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#current_ability, #current_user_notes

Instance Method Details

#createObject



26
27
28
29
30
31
32
33
34
35
36
# File 'app/controllers/homeland/note/notes_controller.rb', line 26

def create
  authorize! :create, Note
  @note = Note.new(note_params)
  @note.user_id = current_user.id
  @note.publish = note_params[:publish] == '1'
  if @note.save
    redirect_to(@note, notice: "创建成功。")
  else
    render action: 'new'
  end
end

#destroyObject



53
54
55
56
57
58
59
# File 'app/controllers/homeland/note/notes_controller.rb', line 53

def destroy
  @note = current_user_notes.find(params[:id])
  authorize! :destroy, @note
  @note.destroy

  redirect_to(notes_url)
end

#editObject



21
22
23
24
# File 'app/controllers/homeland/note/notes_controller.rb', line 21

def edit
  @note = current_user_notes.find(params[:id])
  authorize! :update, @note
end

#indexObject



6
7
8
# File 'app/controllers/homeland/note/notes_controller.rb', line 6

def index
  @notes = current_user_notes.recent_updated.page(params[:page])
end

#newObject



16
17
18
19
# File 'app/controllers/homeland/note/notes_controller.rb', line 16

def new
  authorize! :create, Note
  @note = current_user_notes.build
end

#previewObject



48
49
50
51
# File 'app/controllers/homeland/note/notes_controller.rb', line 48

def preview
  out = Homeland::Markdown.call(params[:body])
  render plain: out
end

#showObject



10
11
12
13
14
# File 'app/controllers/homeland/note/notes_controller.rb', line 10

def show
  @note = ::Note.find(params[:id])
  authorize! :read, @note
  @note.hits.incr(1)
end

#updateObject



38
39
40
41
42
43
44
45
46
# File 'app/controllers/homeland/note/notes_controller.rb', line 38

def update
  @note = current_user_notes.find(params[:id])
  authorize! :update, @note
  if @note.update(note_params)
    redirect_to(@note, notice: "更新成功。")
  else
    render action: 'edit'
  end
end