2

In my development environment my angular pages respond just fine. Once changing my environment to production when I visit my pages with angular content I get an error in the console saying:

Error: [ng:areq] Argument 'SwimmersCtrl' is not a function, got undefined

Here is my modules.js.coffee file:

@comsatrack = angular.module 'comsatrack',
  ['ngResource', 'comsatrackFilters', 'ngAnimate']

Here is my application.js.coffee file:

#= require jquery
#= require jquery.turbolinks
#= require jquery_ujs
#= require bootstrap
#= require turbolinks

#= require angular
#= require angular-resource
#= require angular-animate

#= require modules
#= require_tree .

Here is my swimmers.js.coffee file:

@comsatrack.controller 'SwimmersCtrl', ['$scope', 'Swimmers',
  @SwimmersCtrl = ($scope, Swimmers) ->

$scope.predicate =
  value: 'last_name'

$scope.alerts = []

$scope.addAlert = (swimmer) ->
  $scope.alerts = []
  $scope.alerts.push
    type: "success"
    msg: "#{swimmer.first_name}
          #{swimmer.last_name} has been checked in!"

$scope.closeAlert = (index) ->
  $scope.alerts.splice index, 1

$scope.showPhone = (swimmer) ->
  swimmer.phone_number?

$scope.hideCheckin = (swimmer) ->
  swimmer.phone_number?

$scope.totalDisplayed = 10

$scope.loadMore = ->
  $scope.totalDisplayed += 100

Swimmers.index (data) ->
  $scope.Swimmers = data
]

On the index page I access this controller via:

<div ng-app='comsatrack'>
  <div ng-controller='SwimmersCtrl'>
    <!-- index page content -->
  </div>    
</div>

I have double checked to make sure that I have not double initialized my module anywhere else in my app.

Thank you in advance for any help related to this issue. I would also appreciate any feedback or comments on the code, unrelated to the issue.

1 Answer 1

1

Are your JS files being loaded in the browser and if so, do they have your expected javascript code?

My initial thoughts are around the asset pipeline. Unless you changed the asset pipeline configurations, development environment defaults to compiling assets on the fly (which would load your javascript), while production environments Rails assumes assets have been precompiled and will be served as static assets by your web server. If that's the

$ RAILS_ENV=production bundle exec rake assets:precompile

See Rails Pipeline - Production: http://guides.rubyonrails.org/asset_pipeline.html#in-production

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.