class DigitalAssetsController < ApplicationController include DigitalAssetsHelper respond_to :json skip_filter(*_process_action_callbacks.map(&:filter)) rescue_from 'Mongoid::Errors::DocumentNotFound' do |exception| render json: {errors: [exception.message]}, status: 404 end # GET /digital_assets # GET /digital_assets.json #/digital_assets/search/sami_code=92023 #/digital_assets/search/sami_code=NE00192&title=Fund%20Prospectus&fund_code=20293 def index search_params = params[:search] || request.query_parameters @digital_assets = search_params.present? ? search_da(search_params) : DigitalAsset.all # respond_with(@digital_assets) render json: @digital_assets end alias :search :index # GET /digital_assets/1 # GET /digital_assets/1.json def show @digital_asset = /\w{4,8}\.\d{0,3}/ =~ params[:id] ? DigitalAsset.sami_is(params[:id]).desc(:changed_at).first : DigitalAsset.find(params[:id]) respond_with(@digital_asset) end def update da_passed = params[:digital_asset] da = DigitalAsset.find_or_initialize_by(digital_asset_id: da_passed[:digital_asset_id]) creating = da.new? da.update_attributes! da_passed if(creating) head :created, location: digital_asset_path(da) else head :ok end end alias :create :update def destroy da = DigitalAsset.find(params[:id]) da.delete head :ok end def updated_time if(params[:ids].present?) assets = DigitalAsset.where(:digital_asset_id.in => params[:ids]) else assets = DigitalAsset.all end updated_time = Hash[assets.map{|a| [a.digital_asset_id, a.doc_changed_at]}] render json: updated_time.to_json, status: :ok end def fund_docs @digital_assets = DigitalAsset.fund_docs.where(:fund_codes.ne => []) respond_with(@digital_assets) end end