paloma
paloma copied to clipboard
Howto access params variables?
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]"}};
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.
I just noticed you can also do something like this: https://github.com/kbparagua/paloma#controller-wide-setup