简体   繁体   中英

Use Javascript variable in haml with datamapper

I'm having a little issue here, we are bussy with our internship and are still learning so sorry in advance for some "stupid" questions.

We have a Haml file where we make use of datamapper for our Database. For static views based on our data, we make use of datamapper-code lines in haml.

But now I wanted to use a Javascript variable, who's located in the pageload function, to use this as a parameter with our datamapper code lines in haml.

In our javascript:

$(document).ready(function(){
var ctrpersiteid = $.cookie('sitedata');

Part of our Haml file where we want to use our variable ctrpersiteid

 - Interface.all(:router_id => getRouterId(ctrpersiteid)).each do |interface|
   %h3 #{interface.name}

So is there any way that I could use my Javascript variable in the haml file as parameter for our function ?

The short answer is no. Javascript is only executed in the clients browser, so there's no way to access it from your server-side haml template.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM