I am using rails 2.3 and have a problem. I have remote form, and when I submit it I need to execute some js. Here is my js.erb file
$(document).ready(function () {
$("#block_login").remove();
$("#header").html("");
$("#header").html("<%= render :partial => "/layouts/header" %>");
});
in js console I have an error
> Uncaught SyntaxError: Unexpected identifier jquery.js:593
> jQuery.extend.globalEval jquery.js:593
> jQuery.ajaxSetup.converters.text script jquery.js:7175 ajaxConvert
> jquery.js:7074 done jquery.js:6622 jQuery.ajaxTransport.send.callback
and this is cause of rendering.
Partial works fine, cause I have rendered it in html, and all was fine. Here is my layouts/_header
<div id="header">
<% if current_user.present? %>
<div class="icon_1"><%= link_to 'Выход', logout_path %>
<span>|</span><%= link_to 'Моя страница', user_path(current_user), :class => "registration" %> </div>
<% else %>
<div class="icon_1"><a href="#" onClick="block_login();">Вход</a>
<span>|</span><%= link_to 'Регистрация', new_user_path, :class => "registration" %></div>
<% end %>
<div class="clear"></div>
<table width="100%" cellpadding="0" cellspacing="0">
<tr>
<td width="130px">
<div class="logo"><%= image_tag "/images/logo.png" %></div>
</td>
<td>
<div class="menu">
<table width="100%" cellpadding="0" cellspacing="0">
<tr>
<td>
</td>
</tr>
</table>
</div>
</td>
</tr>
</table>
</div>
What i am doing wrong? THanks in advance!
Maybe it's the quotation marks. Try using:
$("#header").html("<%= render :partial => '/layouts/header' %>");
Instead of your code in:
$("#header").html("<%= render :partial => "/layouts/header" %>");