Z
Z
Zaur Ashurbekov2014-04-29 23:01:51
JavaScript
Zaur Ashurbekov, 2014-04-29 23:01:51

Link_to, ajax and post request?

Hello Habr!
For an hour I can not solve the problem. Help me please. And here's the problem. There is some link that needs to get the form from the Ajax server. But in response to the request, 404 comes out. The link code itself is as follows

= link_to "Редактировать", controller: "navigation", action: "form_for_new_item",  remote: true, method: :post


in routes
post '/navigation/form' => 'navigation#form_for_new_item'


action
def form_for_new_item
     @item = Navigations.new
      respond_to do |format|
         format.js
      end	 
end


js file to send
<%  @item.drop_down = false %>
var form = document.createElement('div')
$(form).append('<%= form_for @item, url: { action: "create_item"} do |form| %>
<%= form.text_field :name %>
<%= form.text_field :url %>
<%= form.text_field :sort_id %>
<%= form.submite "Создать" %> 
<%end%>
')
$(form).dialog("open")


outputs in the console
GET http://0.0.0.0:3000/navigation/form<b>?method=post (???)</b> 404 (Not Found) jquery.js?body=1:9667
send jquery.js?body=1:9667
jQuery.extend.ajax jquery.js?body=1:9212
$.rails.rails.ajax jquery_ujs.js?body=1:81
$.rails.rails.handleRemote jquery_ujs.js?body=1:157
(anonymous function) jquery_ujs.js?body=1:307
jQuery.event.dispatch jquery.js?body=1:4625
elemData.handle

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Marat Amerov, 2014-05-02
@zaurius

need to usebutton_to

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question