0

I have an instance method in my controller, for example

@instance_var =  [{:id=>7142,
  :t_id=>"5888",
  :date=>Mon, 10 Mar 2014,
  :name=>"test"]

From my controller, I have rendered a js to call a partial file.

In this js file, my instance variable is encoded in HTML like " is encoded to " and =>is encoded to =>. That's why I am having problems in calling a partial file with collection. Partial files are not iterating to each instance_var key-value pair.

$('#element_id').html('<%= escape_javascript(render(:partial => "my_partial", :collection => @instance_var)) %>')
Richard Hamilton
  • 25,478
  • 10
  • 60
  • 87
Radix
  • 2,527
  • 1
  • 19
  • 43

1 Answers1

2

You can use raw method that is available in rails. There's also html_safe and some other options, you can read about them here.

Community
  • 1
  • 1
Dabrorius
  • 1,039
  • 1
  • 8
  • 17
  • I cannot use html_safe as I'm in JS file. It says undefined method `html_safe`. I actually want to change my instance variable so that I can use it in `collection` to iterate it in partial file. – Radix Mar 26 '15 at 05:43