5

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?
2
  • Is your partial output actually getting escaped to HTML? Commented Oct 11, 2010 at 21:06
  • yes. And it's not html_safe. I did solve it as i explained in my own answer (see below) Commented Oct 12, 2010 at 12:31

1 Answer 1

4

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?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.