views:

161

answers:

3

I want to display a modal window with an error message, when the user has entered something invalid in a form, but render another action if everything is ok. However, when I try to display the modal window with

 render :js => "jQuery.facebox(#{...})"

only the actual javascript called is displayed:

try {
jQuery.facebox(...)
} catch (e) { alert('RJS error:\n\n' + e.toString()); alert('jQuery.facebox(\"<div class=\'error\'>Error</div>\")'); throw e 
}
A: 

Try this

 render :update do|page|
   page <<  "jQuery.facebox(#{...})"
 end
Salil
Same thing happens.
Ermin
A: 

Maybe you should specify in the jQuery call the dataType of the response you're waiting for.

E.g.:

$.ajax({ 
  url: "/controller/action/id", 
  success: function(){
    $(this).addClass("done");
  },
  dataType: 'script' 
});
Stanislav
A: 

Have you tried putting the code in a partial? So instead of

 render :js => "jQuery.facebox(#{...})"

try

 render :partial => "my_facebox_popup" 

Then inside of your _my_facebox_popup.html.erb partial put your code:

<script type = "text/javascript">
...
</script>

debug any errors you get with firebug. http://getfirebug.com/

ThinkBohemian