Sha256: a80c4dedf990faabe7d88bccfa5ae322fddc56fe17a825102fdb54eb035cf48b

Contents?: true

Size: 729 Bytes

Versions: 4

Compression:

Stored size: 729 Bytes

Contents

module Gmaps4rails
  class GmapsController < ApplicationController
    unloadable    
    
    def index
      @model = params["model"]
      @scope = params["scope"]
      @model = @model.constantize
      
      # The split returns the array [scope_name, arg1, arg2, ...]
      if @scope && !@scope.empty? && @model.gmaps4rails_trusted_scopes.include?(@scope.split(/\(| *, *|\)/)[0])
        object = eval("#{@model}.#{@scope}") # Cannot use send with lambda scope 
                                             # because the arguments have to be separated
        @objects = object.to_gmaps4rails
      else
        @objects = @model.all.to_gmaps4rails
      end 
      
      render :json => @objects
    end        
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
gmaps4rails-0.6.0 app/controllers/gmaps4rails/gmaps_controller.rb
gmaps4rails-0.5.0 app/controllers/gmaps4rails/gmaps_controller.rb
gmaps4rails-0.4.1 app/controllers/gmaps4rails/gmaps_controller.rb
gmaps4rails-0.4.0 app/controllers/gmaps4rails/gmaps_controller.rb