Rails和Angular无法获取URL路由ID

时间:2015-07-04 19:00:28

标签: javascript ruby-on-rails angularjs

我正在尝试从Rails路由传递到页面后从我的Angular路由中获取ID。但是,我在检索id时遇到了问题,并且我已经为url匹配尝试了各种不同的组合。有没有办法让我注销URL并试图弄清楚我应该如何匹配网址?

示例链接:http://localhost:3000/events/dumpling_night

Rails路线:

get '/events/*path' => 'event#event'

角度代码:

var app = angular.module('eventsApp', ['ngRoute', 'templates']);

app.config([
  '$routeProvider', function($routeProvider) {  
    console.log($routeProvider.$get);
    $routeProvider.
     when('/:id', { //trying to render this, but keeps going to .otherwise
        templateUrl: '../templates/eventTemp2.html',
        controller: 'EventsCtrl2'
     }).
     otherwise({
        templateUrl: '../templates/eventTemp.html',
        controller: 'EventsCtrl'
     });
  }
]);
app.controller('EventsCtrl', function($scope, $http){
    console.log('yo!');
});

app.controller('EventsCtrl2', function($scope, $http) {
    console.log('yo2');
});

Rails事件控制器:

class EventController < ApplicationController
    layout "application"
    def event
    end
end

0 个答案:

没有答案