javascript - In Rails, how can we pass parameters in script? -


in java script, can define variable.

var topping = data.getvalue(selecteditem.row, 0); 

and then, want use topping value this:

console.log(<%= @ecs.where(status:topping).count %>); 

obviously, can't work because not find topping. question how should use parameters of script in <%= %>.

you confuse between server side script , client side script. <%= %> server side script. javascript client side script. when rendering page, ruby on rails executes server side script first, send response browser, browser executes client side script later, can't use client side variables in <%= %>.

if want result dynamically based on client side variables. use ajax. send parameter server, , response javascript. it's big picture. see tutorials below(not sure work) or start rails book(agile web development rails) or google it.

rails ajax tutorials


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -