Hi,
I'm using prototype/rjs on rails 2.3.3 and ruby 1.86 and my form_remote_for
to my "create" controller just displays the create.js.rjs instead of executing it. The strange this is that all the other action+rjs's work fine, just the "create" action isn't working Any help would be appreciated. Thanks in advance!
UPDATE: To clarify, it should work: _form submit -> POST -> create method -> js -> load different partial. Instead it is working: _form submit -> POST -> create method -> outputting js as text
_form.html.haml:
- form_remote_for(@network) do |f|
= f.error_messages
%p><
= f.label :name
= f.text_field :name
%p><
= f.label :image_url
= f.text_field :image_url
%p><
= f.label :url
= f.text_field :url
%p><
= f.submit "Create"
create.js.rjs:
page.insert_html(:bottom, :networks, :partial => 'networks/network', :object => @network);
networks_controller:
def create
@network = Network.new(params[:network])
respond_to do |format|
if @network.save
flash[:notice] = 'Network was successfully created.'
format.js #also doesn't work with { render :layout => false }
else
format.html { render :action => "new" }
format.xml { render :xml => @network.errors, :status => :unprocessable_entity }
format.js
end
end
end
output (it displays as html):
try {
Element.insert("networks", { bottom: "<div class='network'>\n <img alt=\"Df\" src=\"/images/df\" />\n <a href=\"d\">wer</a>\n <a href=\"/networks/39\">Show</a>\n <a href=\"/networks/39/edit\">Edit</a>\n <a href=\"/networks/39\" onclick=\"if (confirm('Are you sure?')) { var f = document.createElement('form'); f.style.display = 'none'; this.parentNode.appendChild(f); f.method = 'POST'; f.action = this.href;var m = document.createElement('input'); m.setAttribute('type', 'hidden'); m.setAttribute('name', '_method'); m.setAttribute('value', 'delete'); f.appendChild(m);var s = document.createElement('input'); s.setAttribute('type', 'hidden'); s.setAttribute('name', 'authenticity_token'); s.setAttribute('value', 'dfleb/EzulRpXnZekVfbhAkX3G9jHmhnWTBLSk7iRSE='); f.appendChild(s);f.submit(); };return false;\">Destroy</a>\n</div>\n" });
} catch (e) { alert('RJS error:\n\n' + e.toString()); alert('Element.insert(\"networks\", { bottom: \"<div class=\'network\'>\\n <img alt=\\\"Df\\\" src=\\\"/images/df\\\" />\\n <a href=\\\"d\\\">wer</a>\\n <a href=\\\"/networks/39\\\">Show</a>\\n <a href=\\\"/networks/39/edit\\\">Edit</a>\\n <a href=\\\"/networks/39\\\" onclick=\\\"if (confirm(\'Are you sure?\')) { var f = document.createElement(\'form\'); f.style.display = \'none\'; this.parentNode.appendChild(f); f.method = \'POST\'; f.action = this.href;var m = document.createElement(\'input\'); m.setAttribute(\'type\', \'hidden\'); m.setAttribute(\'name\', \'_method\'); m.setAttribute(\'value\', \'delete\'); f.appendChild(m);var s = document.createElement(\'input\'); s.setAttribute(\'type\', \'hidden\'); s.setAttribute(\'name\', \'authenticity_token\'); s.setAttribute(\'value\', \'dfleb/EzulRpXnZekVfbhAkX3G9jHmhnWTBLSk7iRSE=\'); f.appendChild(s);f.submit(); };return false;\\\">Destroy</a>\\n</div>\\n\" });'); throw e }
Update:
_networks.html.haml:
%div{:id=> 'network#{network.id}', :name => 'network'}
= image_tag network.image_url
= link_to network.name, network.url
- if logged_in? && self.current_user.login = "admin"
= link_to 'Show', network
= link_to 'Edit', network_path(network), :method => :put, :class => "put"
= link_to 'Destroy', network_path(network), :method => :delete, :class => "delete"
%br