Skip to content

Instantly share code, notes, and snippets.

@davetron5000
Created February 6, 2015 15:11
Show Gist options
  • Save davetron5000/2302a350c486457a4a5d to your computer and use it in GitHub Desktop.
Save davetron5000/2302a350c486457a4a5d to your computer and use it in GitHub Desktop.

Rails routes:

root 'home#index'

app/views/home/index.html.erb:

<div ng-app="receta">
  <div class="view-container">
    <div ng-view class="view-frame animate-view"></div>
  </div>
</div>

Angular routes:

 $routeProvider
      .when('/',
        templateUrl: "index.html"
        controller: 'RecipesController'
      ).when('/recipes/new',
        templateUrl: "form.html"
        controller: 'RecipeController'
      ).when('/recipes/:recipeId',
        templateUrl: "show.html"
        controller: 'RecipeController'
      ).when('/recipes/:recipeId/edit',
        templateUrl: "form.html"
        controller: 'RecipeController'
      )

So, if you go to /, it kill kick off the HomeController's index action, which renders that basic HTML to bootstrap the angular app. Angular will likely change the url to /#/, and whatever is after the # is angular's route. In this case it is also / so you get the index.html view of RecipesController.

Now, if your url is /#/recipes/3, the Rails route is still / and thus is still being served by HomeController's index method, but the Angular route (which is everything after #) is /recipes/3, which matches /recipes/:recipeId which means we get the show.html view of RecipeController.

It's slightly confusing, but the # is what divides the two systems' routing schems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment