class Api::V1::NotesController

Public Instance Methods

create() click to toggle source
# File lib/generators/jinda_engine/templates/app/controllers/api/v1/notes_controller.rb, line 23
def create
  @note = Note.new(
    title: params[:title],
    body: params[:body],
    user_id: params[:user])

  @note.save!
  render json: @note, status: :created
end
delete() click to toggle source
# File lib/generators/jinda_engine/templates/app/controllers/api/v1/notes_controller.rb, line 46
def delete
  # called by freemind
# Tobe called from other controller:jinda
  @note_id = $xvars["select_note"] ? $xvars["select_note"]["id"] : $xvars["p"]["note_id"]
  @note = Note.find(@note_id)
  @note.destroy
end
destroy() click to toggle source
# File lib/generators/jinda_engine/templates/app/controllers/api/v1/notes_controller.rb, line 54
def destroy
  # called by rails menu my
  if current_ma_user.role.upcase.split(',').include?("A") || current_ma_user == @note.user
    @note.destroy
  end
  redirect_to :action=>'my'
end
edit() click to toggle source
# File lib/generators/jinda_engine/templates/app/controllers/api/v1/notes_controller.rb, line 18
def edit
  @note = Note.find(params[:id])
  @page_title       = 'Edit Note'
end
index() click to toggle source

before_action :xload_current_ma_user, only: [:destroy]

# File lib/generators/jinda_engine/templates/app/controllers/api/v1/notes_controller.rb, line 5
def index
  @notes = Note.desc(:created_at).page(params[:page]).per(10)
  render json: @notes
end
mail() click to toggle source
# File lib/generators/jinda_engine/templates/app/controllers/api/v1/notes_controller.rb, line 62
def mail
  NoteMailer.gmail(
                  $xvars["display_mail"]["body"],
                  $xvars["select_note"]["email"],
                  $xvars["display_mail"]["title"],
                  xload_current_ma_user.email)
end
my() click to toggle source
# File lib/generators/jinda_engine/templates/app/controllers/api/v1/notes_controller.rb, line 10
def my
  @notes = Note.where(user_id: current_ma_user).desc(:created_at).page(params[:page]).per(10)
  render json: @notes
end
show() click to toggle source
# File lib/generators/jinda_engine/templates/app/controllers/api/v1/notes_controller.rb, line 15
def show 
end
update() click to toggle source
# File lib/generators/jinda_engine/templates/app/controllers/api/v1/notes_controller.rb, line 34
def update
  # $xvars["select_note"] and $xvars["edit_note"]
  # These are variables.
  # They contain everything that we get their forms select_note and edit_note
  note_id = $xvars["select_note"] ? $xvars["select_note"]["id"] : $xvars["p"]["note_id"]
  @note = Note.find(note_id)
  @note.update(title: $xvars["edit_note"]["title"],
               body: $xvars["edit_note"]["body"])
  redirect_to @note

end

Private Instance Methods

load_note() click to toggle source
# File lib/generators/jinda_engine/templates/app/controllers/api/v1/notes_controller.rb, line 77
def load_note
  @note = Note.find(params[:id])
end
xload_current_ma_user() click to toggle source

Tobe called from other controller:jinda

# File lib/generators/jinda_engine/templates/app/controllers/api/v1/notes_controller.rb, line 73
def xload_current_ma_user
  @current_ma_user = User.find($xvars["user_id"])
end