1

EDIT: Restangular depends on Lodash or Underscore!! Once I installed Lodash things are working


How? I just want to do a basic hookup to get going...

So here's my controller

AngulaRails.controller "BooksController", ($scope, Restangular) ->

allbooks = Restangular.all('books')

$scope.getBooks = ()  ->
  allbooks.getList().then (response) ->
    console.log(response)
    $scope.books = response

Here's my view in rails (I'm not messing with routes in angular, just to keep things simple):

<div ng-app="AngulaRails" ng-controller="BooksController" ng-init= "getBooks()">
  <h3>booksbooksbooks</h3>
  <div>{{ books }}</div>
</div>

You see I'm calling the getBooks() function, as defined in the controller

Here's my rails controller:

class BooksController < ApplicationController
  before_action :set_book, only: [:show, :edit, :update, :destroy]


  # GET /books
  def index
    @books = Book.all
    @pages = Page.all

    respond_to do |format|
      format.html {}
      format.json {render json: @books, root: false, each_serializer: BookSerializer }

    end
  end

I know there is some weird stuff in there about the root and serializer and whatnot, but I've also tried just render json: @books to no avail.

My browser will show the Booksbooksbooks and then just literally {{ books }} Here is the error message from my console:

Error: [$injector:modulerr] http://errors.angularjs.org/1.2.8/$injector/modulerr?p0=AngulaRails&p1=%5B%24injector%3Amodulerr%5D%20http%3A%2F%2Ferrors.angularjs.org%2F1.2.8%2F%24injector%2Fmodulerr%3Fp0%3Drestangular%26p1%3D_%2520is%2520not%2520defined%250Aa.init%2540http%253A%252F%252Flocalhost%253A3000%252Fassets%252Frestangular.min.js%253Fbody%253D1%253A7%253A577%250A%2540http%253A%252F%252Flocalhost%253A3000%252Fassets%252Frestangular.min.js%253Fbody%253D1%253A7%253A10268%250Ad%2540http%253A%252F%252Flocalhost%253A3000%252Fassets%252Fangular.min.js%253Fbody%253D1%253A31%253A451%250Ag%252F%253C.instantiate%2540http%253A%252F%252Flocalhost%253A3000%252Fassets%252Fangular.min.js%253Fbody%253D1%253A32%253A585%250Ac%2540http%253A%252F%252Flocalhost%253A3000%252Fassets%252Fangular.min.js%253Fbody%253D1%253A29%253A499%250Aa%252F%253C%2540http%253A%252F%252Flocalhost%253A3000%252Fassets%252Fangular.min.js%253Fbody%253D1%253A29%253A438%250Ae%252F%253C%2540http%253A%252F%252Flocalhost%253A3000%252Fassets%252Fangular.min.js%253Fbody%253D1%253A30%253A302%250Aq%2540http%253A%252F%252Flocalhost%253A3000%252Fassets%252Fangular.min.js%253Fbody%253D1%253A8%253A276%250Ae%2540http%253A%252F%252Flocalhost%253A3000%252Fassets%252Fangular.min.js%253Fbody%253D1%253A30%253A123%250Ae%252F%253C%2540http%253A%252F%252Flocalhost%253A3000%252Fassets%252Fangular.min.js%253Fbody%253D1%253A30%253A181%250Aq%2540http%253A%252F%252Flocalhost%253A3000%252Fassets%252Fangular.min.js%253Fbody%253D1%253A8%253A276%250Ae%2540http%253A%252F%252Flocalhost%253A3000%252Fassets%252Fangular.min.js%253Fbody%253D1%253A30%253A123%250A%2524b%2540http%253A%252F%252Flocalhost%253A3000%252Fassets%252Fangular.min.js%253Fbody%253D1%253A33%253A238%250AZb%252Fc%2540http%253A%252F%252Flocalhost%253A3000%252Fassets%252Fangular.min.js%253Fbody%253D1%253A18%253A437%250AZb%2540http%253A%252F%252Flocalhost%253A3000%252Fassets%252Fangular.min.js%253Fbody%253D1%253A19%253A141%250ATc%2540http%253A%252F%252Flocalhost%253A3000%252Fassets%252Fangular.min.js%253Fbody%253D1%253A18%253A220%250A%2540http%253A%252F%252Flocalhost%253A3000%252Fassets%252Fangular.min.js%253Fbody%253D1%253A202%253A125%250AjQuery.Callbacks%252Ffire%2540http%253A%252F%252Flocalhost%253A3000%252Fassets%252Fjquery.js%253Fbody%253D1%253A3120%253A1%250AjQuery.Callbacks%252Fself.fireWith%2540http%253A%252F%252Flocalhost%253A3000%252Fassets%252Fjquery.js%253Fbody%253D1%253A3232%253A7%250A.ready%2540http%253A%252F%252Flocalhost%253A3000%252Fassets%252Fjquery.js%253Fbody%253D1%253A3444%253A3%250Acompleted%2540http%253A%252F%252Flocalhost%253A3000%252Fassets%252Fjquery.js%253Fbody%253D1%253A3475%253A3%250A%0AF%2F%3C%40http%3A%2F%2Flocalhost%3A3000%2Fassets%2Fangular.min.js%

I'm getting the sense that Restangular isn't even getting used...

EDIT: Restangular depends on Lodash or Underscore!! Once I installed Lodash it's working

2
  • Never used Restangular, so this may be a nuance, but glancing at the docs it looks like your usage of all is reversed. Should it not be Restangular.all('books')? Commented Jul 3, 2014 at 22:46
  • Yes and yes.... but unfortunately I'm still getting the same error. The docs on that error say that it means 'failed to instantiate AngulaRails Module' Which is my specific angularails app Commented Jul 3, 2014 at 22:55

1 Answer 1

2

You need to suply lodash, it is a dependency of restangular

in application.js

//= require lodash/dist/lodash.min
//= require angular/angular
//= require restangular/dist/restangular
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.