title: Calling a Rails function from an Angular service
body: <p>If have a simple Rails controller defined like so:</p>
  
  <pre><code>class ProductsController &lt; ApplicationController
  
    respond_to :json
  
    def index
    end
  
    def new
    end
  
    def create
      @product = Product.new(product_params)
      @product.save
      redirect_to @product
  
      # this can be used if there is no view already created 
      # render plain: params[:products].inspect
    end
  
    def show
      @product = Product.find(params[:id])
      respond_with @product
    end
  
    def show_all
      # @products = Product.all
      # respond_with @products
      respond_to do |format|
        @products = Product.all
  
        format.html 
        format.json { render json: @products }
      end
    end
  
    private
        def product_params
          params.require(:product).permit(:name, :description)
        end
  end
  </code></pre>
  
  <p>I have attempted to use this in my Angular service by doing the following:</p>
  
  <pre><code>function HomeService($resource) {
      function exposeTest() {
          /*
          {
              'create':  { method: 'POST' },
              'index':   { method: 'GET', isArray: true },
              'show':    { method: 'GET', isArray: false },
              'update':  { method: 'PUT' },
              'destroy': { method: 'DELETE' }
          }
          */
          return $resource('/products/show_all', {}, {
              'show_all':     { method: 'GET', isArray: false }
          });
      }
      return {
          exposeTest: exposeTest
      };
  }
  </code></pre>
  
  <p>And I call this in my home.controller.js like so:</p>
  
  <pre><code>console.log('Expose Test: '+JSON.stringify(HomeService.exposeTest().show_all()));
  </code></pre>
  
  <p>It's my understanding that you can define a $resource object to interact with the controller - i.e. I have defined a GET type method which can be called with show_all but all I get back is an empty object.</p>
  
  <p>What am I doing wrong? </p>
  
  <p>Thanks</p>