paloma icon indicating copy to clipboard operation
paloma copied to clipboard

Howto access params variables?

Open niksfirefly opened this issue 8 years ago • 2 comments

I set some variables params in before_action ApplicationController so they are accessible in entire app for every Paloma controller.

js user: username, email: email

How can i access this params with other js functions outside of Paloma controllers? I want them to be accessible for all pages - not specific ones. I see them passed to html-js script, for example:

request = {"resource":"Test","action":"index","params":{"user":"admin","email":"[email protected]"}};

niksfirefly avatar Jun 03 '16 13:06 niksfirefly

Hi @niksfirefly!

I don’t think that’s possible… At least, it doesn’t look like something that Paloma supports by default (you seem like you want global variables). Do you want them to be accessible by every JS function in your app, or only every action a Paloma controller might have? However, have you tried to set those parameters as global variables in other way? Something like:

Paloma.controller('Application', {
  before: ['all -> init'],
  init: function () {
    var params = this.params;

    Object.keys(params).forEach(function (key) {
      window[key] = params[key];
    });
  },
});

It’s not pretty, and I haven’t tested it, honestly. But it’s very close to what I would write for this case, if necessary.

gnclmorais avatar Jun 15 '16 14:06 gnclmorais

I just noticed you can also do something like this: https://github.com/kbparagua/paloma#controller-wide-setup

gnclmorais avatar Jun 21 '16 14:06 gnclmorais