Cancan on a single page application

What is the correct way to test the ability of a single application (backbone.js)?

eg. if it was not a one-page application, I could write on a template

<% if can :read? @resource %> <%= link_to @resource %> <% end %> 

But my problem is that I have not loaded @resource when I create the client template.

+4
source share
1 answer

As a rule, access control will be performed both on the client and on the server. On the server you can use authorize! in their controllers according to normal. On the client, cancan is unavailable.

Possible solutions:

  • Rendering view fragments on a server, where can? available. I do not think this approach is very important with the spine.
  • Open API for "cancan requests"
  • Duplicate your ability object on the client

I lean over the lines, exposing the API, but if the network becomes a performance issue, I think you will have to duplicate your object object on the client side.

This seems like a good example of how client-side applications work more!

+3
source

Source: https://habr.com/ru/post/1483289/


All Articles