Class: Admin::NotesController

Inherits:
CrudController
  • Object
show all
Defined in:
app/controllers/admin/notes_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject


24
25
26
27
28
29
30
# File 'app/controllers/admin/notes_controller.rb', line 24

def create
  @note = current_user.notes.new(note_params)
  @note.note = view_context.markdown(@note.note).gsub("\n","").gsub("\r","")
  @note.save
  $statsd.increment 'animal.note.created'
  respond_with(@note)
end

#destroyObject


32
33
34
35
36
37
38
# File 'app/controllers/admin/notes_controller.rb', line 32

def destroy
  @note = Note.find(params[:id])
  @note.destroy
  flash[:notice] = 'Successfully destroyed note.'
  
  redirect_to :back
end

#indexObject


13
14
15
16
17
18
19
20
21
22
# File 'app/controllers/admin/notes_controller.rb', line 13

def index
  if params[:animal_id]
    @search = Note.includes(:animal).where(animal_id: params[:animal_id]).search(params[:q])
  else  
    @search = Note.includes(:animal).where(user_id: current_user.id).search(params[:q])
  end
  @notes = @search.result.paginate(:page => params[:page], :per_page => 10).order("updated_at DESC")

  respond_with(@notes)
end