Sunday, January 12, 2014

Redmine:: passing ruby variable to javascript

I needed to get user's first name from database and pass the value to a javascript variable in JSON format.

I wanted to exclude the root, so I used this line.


ActiveRecord::Base.include_root_in_json = false


then I declared a ruby variable named token which takes id and firstname attribute from user table,

  @token = User.all.to_json(only: [:id, :firstname])


In the erb file, I used the following line,

var tokenList = <%= @token.html_safe %>







No comments: