Last active
November 12, 2015 10:27
-
-
Save megamos/655f3547e34f5eb617a1 to your computer and use it in GitHub Desktop.
Failing to pass routing from rails(backend) over to angularJS. On page refresh rails does the routing instead of angular.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ApplicationController < ActionController::Base | |
# Prevent CSRF attacks by raising an exception. | |
# For APIs, you may want to use :null_session instead. | |
protect_from_forgery with: :exception | |
def index | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module( 'allapassApp' ).controller 'CompanyCtrl', ($scope, Company) -> | |
$scope.test = 'Test passed!!' | |
$scope.companies = [] | |
$scope.company2 = [] | |
$scope.locals = ['Yogacenter', 'DanceCenter', 'MeditationCenter'] | |
#Put all Companies in an array | |
Company.query().then (result) -> $scope.companies = result | |
# Show company with id = 2 | |
Company.get(2).then (result) -> $scope.company2 = result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Started GET "/" for 127.0.0.1 at 2015-11-12 11:23:29 +0100 | |
Processing by ApplicationController#index as HTML | |
Rendered application/index.html.erb within layouts/application (0.1ms) | |
Completed 200 OK in 225ms (Views: 224.0ms | ActiveRecord: 0.0ms) | |
Started GET "/companies" for 127.0.0.1 at 2015-11-12 11:23:33 +0100 | |
Processing by CompaniesController#index as JSON | |
Parameters: {"company"=>{}} | |
Company Load (0.9ms) SELECT "companies".* FROM "companies" | |
Completed 200 OK in 12ms (Views: 7.1ms | ActiveRecord: 0.9ms) | |
Started GET "/companies/2" for 127.0.0.1 at 2015-11-12 11:23:33 +0100 | |
Processing by CompaniesController#show as JSON | |
Parameters: {"id"=>"2", "company"=>{}} | |
Company Load (0.6ms) SELECT "companies".* FROM "companies" WHERE "companies"."id" = $1 LIMIT 1 [["id", 2]] | |
Completed 200 OK in 6ms (Views: 1.1ms | ActiveRecord: 0.6ms) | |
Started GET "/companies" for 127.0.0.1 at 2015-11-12 11:23:38 +0100 | |
Processing by CompaniesController#index as HTML | |
Completed 406 Not Acceptable in 1ms (ActiveRecord: 0.0ms) | |
ActionController::UnknownFormat - ActionController::UnknownFormat: | |
responders (2.1.0) lib/action_controller/respond_with.rb:205:in `respond_with' | |
app/controllers/companies_controller.rb:7:in `index | |
..... | |
.... | |
..... (error lines continue) ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('allapassApp').config ($stateProvider, $urlRouterProvider, $locationProvider) -> | |
# Home routes | |
$stateProvider.state('home', | |
url: '/' | |
templateUrl: 'components/home/home.html' | |
controller: 'HomeCtrl' | |
redirectTo: (current, path, search) -> | |
if search.goto | |
# if we were passed in a search param, and it has a path | |
# to redirect to, then redirect to that path | |
'/' + search.goto | |
else | |
# else just redirect back to this location | |
# angular is smart enough to only do this once. | |
'/' | |
) | |
.state('dashboard', | |
abstract: true | |
url: '/dashboard' | |
templateUrl: 'shared/navbar/dashboard/layout.html') | |
.state('dashboard.one', | |
url: '' | |
templateUrl: 'shared/navbar/dashboard/one.html') | |
.state('dashboard.two', | |
url: '/two' | |
templateUrl: 'shared/navbar/dashboard/two.html') | |
.state('dashboard.three', | |
url: '/three' | |
templateUrl: 'shared/navbar/dashboard/three.html') | |
# Company routes | |
$stateProvider.state('companies', | |
url: '/companies' | |
templateUrl: 'components/company/companies.html' | |
controller: 'CompanyCtrl') | |
$stateProvider.state('new', | |
url: '/companies/new' | |
templateUrl: 'components/company/new.html' | |
controller: 'CompanyCtrl') | |
$stateProvider.state('company', | |
url: '/companies/:id' | |
templateUrl: 'components/company/company.html' | |
controller: 'CompanyCtrl') | |
# default fallback route | |
$urlRouterProvider.otherwise '/' | |
# enable HTML5 mode for SEO | |
$locationProvider.html5Mode true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Rails.application.routes.draw do | |
resources :companies do | |
resources :locals | |
end | |
# get '*path.html' => 'application#index', :layout => 0 | |
# get '*path' => 'application#index' | |
match "*path" => redirect("/?goto=%{path}"), via: [:get,:post] | |
root 'application#index' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment