Class: NotesController

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

Instance Method Summary collapse

Methods inherited from ApplicationController

#fresh_when, #redirect_back_or_default, #redirect_referrer_or_default, #render_403, #render_404, #render_optional_error_file, #require_user, #set_active_menu, #set_locale, #set_seo_meta, #store_location, #unread_notify_count

Instance Method Details

#createObject


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

def create
  @note = current_user.notes.new(note_params)
  @note.publish = note_params[:publish] == '1'
  if @note.save
    redirect_to(@note, notice: t('common.create_success'))
  else
    render action: 'new'
  end
end

#destroyObject


49
50
51
52
53
54
# File 'app/controllers/notes_controller.rb', line 49

def destroy
  @note = current_user.notes.find(params[:id])
  @note.destroy

  redirect_to(notes_url)
end

#editObject


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

def edit
  @note = current_user.notes.find(params[:id])
  set_seo_meta("修改 » #{t('menu.notes')}")
end

#indexObject


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

def index
  @notes = current_user.notes.recent_updated.paginate(page: params[:page], per_page: 20)
  set_seo_meta t('menu.notes')
end

#newObject


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

def new
  @note = current_user.notes.build
  set_seo_meta("新建 » #{t('menu.notes')}")
end

#previewObject


45
46
47
# File 'app/controllers/notes_controller.rb', line 45

def preview
  render plain: MarkdownTopicConverter.convert(params[:body])
end

#showObject


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

def show
  @note = Note.find(params[:id])
  @note.hits.incr(1)
  set_seo_meta("查看 » #{t('menu.notes')}")
end

#updateObject


36
37
38
39
40
41
42
43
# File 'app/controllers/notes_controller.rb', line 36

def update
  @note = current_user.notes.find(params[:id])
  if @note.update_attributes(note_params)
    redirect_to(@note, notice: t('common.update_success'))
  else
    render action: 'edit'
  end
end