I am trying to access Ruby class attributes in a JS/JQ file.
Example:
class my_class
attr_acessor :my_attr
end
In the Javascript, how can I access and modify this?
$('my_class').???
ANSWER FOR UPDATED QUESTION
You cannot modify a Ruby object from JavaScript.
ANSWER FOR ORIGINAL QUESTION
You need to embed your Ruby code in JavaScript. Your js/html file must end in js.erb or html.erb.
Here is a quick example:
<script>
var javascript_variable_attr = <%= @instance_of_my_class.my_attr %>
</script>
And FYI you cannot modify the Ruby object because you are not accessing the object in memory. Embedding Ruby will simply render the value into the js/html file. In other words, it is read only.
erb, huh?mustache if you don't like erb. It's much cleaner. But at a low level it's basically the same thing. github.com/mustache/mustache