Can you create routes for an Angular application on a Rails server without duplicating the logic?

We have an angular app along with angular routing. However, we need to do things like sending links in emails or via Twitter. They must be run from a server for which server-side route creation is required.

This means that we need to either duplicate the routing logic and path helpers that are currently contained in our angular routing file, or find a way to parse the angular routing file on the server, and then create the ruby ​​path_helper methods.

Is there an easy way to do this - some Rails plugin or similar?

Change (specify)

I need to be able to create links to pages on the server and during cron jobs. If it were a rails application, I could use path helpers, for example edit_user_path @user.

The problem is that the routing logic is now in Angular. Thus, there is no way to generate tracks on the side of the rails. I need to do something. This cannot be done from the client, since the client will not be present - this can be activated from the cron job

+4
source share
2 answers

I assume that you want the user to be able to delete myapp.com/something/unique-333/ as a URL.

, URL . URL- (/unique-333) , , URL-.

, , URL- , .

:

/* REST API */
function get_url_prefix() {
  return '/something/';
}
function get_obj() {
  return JsonResponse({
    'data': obj,
    'url': get_url_prefix() + obj.id + '/';
  });
}

AngularJS:

.config(function($routeConfig, restApi) {
  restApi.get_url_prefix().then(function(urlPrefix) {
    $routeConfig = {
      urlPrefix: CtrlToHandleUniqueRoutes
    };
  });
});

URL-. , URL- .

+1

Rails, JSRoutes, BackboneJS/Rails. Rails . , , - , .

0

All Articles