Ошибка RJS в рельсах - PullRequest
       25

Ошибка RJS в рельсах

1 голос
/ 21 сентября 2011

Я работаю в rails 2.3.8, и я получил следующую ошибку rjs в моем приложении rails.

RJS error:
TypeError: $("#create_event_dialog") is nul

Тогда я нажимаю "ОК", затем иду другой.

Element.update("create_event", "<form action=\"/countries\" class=\"new_country\"   id=\"new_country\" method=\"post\" onsubmit=\"new Ajax.Request('/countries', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this)}); return false;\"><div style=\"margin:0;padding:0;display:inline\"><input name=\"authenticity_token\" type=\"hidden\" value=\"qWXCu2zMmlMhJG+GRf35kMbAIfzYAtFBee142ThmmMw=\" /></div>\n <p>\n    <label for=\"country_name\">Name</label><br />\n    <input id=\"country_name\" name=\"country[name]\" size=\"30\" type=\"text\" />\n  </p>\n  <p>\n    <input id=\"country_submit\" name=\"commit\" type=\"submit\" value=\"Create\" />\n  </p>\n</form>");
$('#create_event_dialog').dialog({
    title: 'New Event',
    modal: true,
    width: 500,
    close: function(event, ui) { $('#create_event_dialog').dialog('destroy') }

});

Вот мой код ...

<%= link_to_remote 'Add new countries', :url => {:controller => 'countries', :action => 'new'} %>

<div id = "create_event_dialog" style ="display:none;">
<div id = "create_event"></div>
</div>

new.js.rjs ::

page.replace_html 'create_event', :partial => 'form'
page<< "$('#create_event_dialog').dialog({
    title: 'New Event',
    modal: true,
    width: 500,
    close: function(event, ui) { $('#create_event_dialog').dialog('destroy') }

});"

create.js.rjs

if @country
if @country.save

page<<"$('#create_event_dialog').dialog('destroy')"
else
page.alert @country.errors.full_messages(',').join("\n")
end
end

_form.html.erb

<%remote_form_for @country, :url => {:controller => 'countries', :action => 'create' } do |f| %>
<p>
<%= f.label :name %><br />
<%= f.text_field :name %>
</p>
<p>
<%= f.submit 'Create' %>
</p>
<% end %>

Кто-нибудь может мне помочь? Почему я получил эту ошибку?

...