Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to pass html_safe strings in js render partials

I have a rails 2.3.9 application that i'm migrating to rails 3.

As almost everyone, i'm having problem with rendering strings, specially JQUERY scripts that were inline. Before, that somebody tells me that in rails 3, it changed, i cannot rewrite all my scripts now. I will do it, it will be scheduled, but for now, i want to make it works.

Going to my question:

i have a controller with the following piece of code

respond_to do |format|
 format.js { render :partial=>'update'}
 format.html { head 406 }
end

My _update.js.erb has a mix between JS and ERB:

<% if MyClass.count > 0 %>
 $('.show_object:visible').hide();
<%else%>
  if($('.show_object').css('display') == 'none'){
   $('.show_object').blink({times: 7})
  }
<%end%>

It works in rails 2.3.9, but not in Rails 3. My question are:

  • should i put around all my jquery a html_safe call?
  • there is a way in the controller to mark a whole partial as html_safe?
like image 830
VP. Avatar asked Oct 14 '22 22:10

VP.


1 Answers

I did solve it doing in my controller:

format.js { 
 render :js=> { render_to_string(:partial=>'update').html_safe!}
} 

it works but don't looks like a good solution. Any other idea?

like image 66
VP. Avatar answered Oct 18 '22 03:10

VP.