1

With rails code:

= button_to "-", availability_time_span_path(ts) ,:method  =>  :delete, :remote  =>  true

I generate html form, which should be posted via ajax:

<form action="/availability_time_spans/175" class="button_to" data-remote="true" method="post">
  <div>
    <input name="_method" type="hidden" value="delete">
    <input type="submit" value="-">           
    <input name="authenticity_token" type="hidden" value="n962qRxizeXeoEwWYv2AlMfT4nKxxp9ITUxm5wp1nZo=">
  </div>
</form>

When I click on the submit button it is posted twice. Once as: text/javascript from jquery.js:8417 , second time as: text/html from Other

2
  • use <input type="button" value="-"> and see if it works Commented Oct 24, 2012 at 13:56
  • What rails code should I use to generate this? If I just paste the already generated html form and set the type to "button", the form is not submitted at all. Commented Oct 24, 2012 at 14:13

2 Answers 2

1

SOLVED

Problem was I previously inject code using ajax, but renderer response with layout, so the whole jquery was initialized for the second time.

respond_with @ra

If I render response to ajax call with no layout, then it is fine.

respond_with @ra, :layout => false 
Sign up to request clarification or add additional context in comments.

Comments

0

This could happen for a couple of reasons

  1. You might have the Javascript cached in your browser. Try clearing your cache or opening the page up in a different browser.
  2. You might be serving up precompiled assets. Make sure you have config.serve_static_assets = false in your config file.

1 Comment

I think this is the right direction since in web inspector it shows me jquery.js:2678 and undefined:2678 as event listeners to all events. It could be that jquery is loaded or initialized twice. Clearing cache did not help and config.serve_static_assets is set to false.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.