class NoteFilesController < ApplicationController
  # GET /note_files
  # GET /note_files.json
  def index
    @note_files = NoteFile.all

    respond_to do |format|
      format.html # index.html.erb
      format.json { render json: @note_files }
    end
  end

  # GET /note_files/1
  # GET /note_files/1.json
  def show
		@note_file = NoteFile.find(params[:id])
		
    
    if params[:inline] and !params[:force]
      
    else
      send_file @note_file.file.path, :filename => @note_file.abstract_file_name_slug, :disposition => (params[:download] ? "attachment" : "inline")
    end
    
  end

  # GET /note_files/new
  # GET /note_files/new.json
  def new
    @note_file = NoteFile.new

    respond_to do |format|
      format.html # new.html.erb
      format.json { render json: @note_file }
    end
  end

  # GET /note_files/1/edit
  def edit
    @note_file = NoteFile.find(params[:id])
  end

  # POST /note_files
  # POST /note_files.json
  def create

    @note_file = NoteFile.new(:original_filename => params[:note_file][:file][0].original_filename ,:name => params[:note_file][:file][0].original_filename, :note_id => params[:note_file][:note_id], :file =>params[:note_file][:file][0])

    if @note_file.save
     
    else
     
    end

  end

  # PUT /note_files/1
  # PUT /note_files/1.json
  def update
    @note_file = NoteFile.find(params[:id])

    respond_to do |format|
      if @note_file.update_attributes(params[:note_file])
        format.html { redirect_to @note_file, notice: 'Note file was successfully updated.' }
        format.json { head :no_content }
      else
        format.html { render action: "edit" }
        format.json { render json: @note_file.errors, status: :unprocessable_entity }
      end
    end
  end

  # DELETE /note_files/1
  # DELETE /note_files/1.json
  def destroy
    @note_file = NoteFile.find(params[:id])
    @note_file.destroy

  end
end
