I am looping instance variable "@packages" set in controller and am trying to assign single object into one of the html element by using "data-". For changing ruby object into json i am using ".to_json" as follows:
<% @packages.each do |package| %>
<% json_package=package.to_json %>
<a href="#" data-single-package=<%= json_package %>></a>
<% end %>
However, on inspecting the anchor tag i found json object is cutting off in one of the property which had a value with space in between it.
As you can see, "title" property has value "annarpurna circuit", but ".to_json" is cutting off in space by adding ".
How can i make this whole string pass through??
Aucun commentaire:
Enregistrer un commentaire