简体   繁体   中英

Rails 3.1.3: Evaluate ruby code before JavaScript

I have controller say Home_controller providing @max = 10 @min=4. And then I later used these two values in my Home.js.erb file rests in /asset/javascript.

values= [<%=@max%>,<%=@min%>]

But it doesn't seem to be working, because when I look at the resultant javascript file from firebug, wherever I have @max or @min , they just show up as blank.

What's going on here? I am new to rails asset pipeline, so I may have some misunderstanding here.

Rails passes the instance variables from Controller to View . So, you want to place the home.js.erb in the views folder and not in the assets.

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