开发者

how to pass html_safe strings in js render partials

开发者 https://www.devze.com 2023-01-19 06:50 出处:网络
I have a rails 2.3.9 application that i\'m migrating to rails 3. As almost everyone, i\'m having problem with ren开发者_高级运维dering strings, specially JQUERY scripts that were inline. Before, that

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

As almost everyone, i'm having problem with ren开发者_高级运维dering 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?


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?

0

精彩评论

暂无评论...
验证码 换一张
取 消