我在rails 2.3.8中工作,我在rails应用程序中遇到了rjs错误。
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 %>
任何人都可以帮助我吗?为什么我会收到此错误?