0

For the sake of argument, we have "new product" form.

I use some javascript libraries for html form elements (e.g. icheck, select2, wysihtml5). These form elements needed to be run with their associated js library functions to show properly (e.g. $(".checkbox").iCheck({...}) ) before rendering the HTML page.

If there is validation errors on submitting the form, Rails will render action "new" to reshow "new product" form with errors (exactly in the "Create" method in "ProductsController").

The problem is Rails will not execute associated javascript files (e.g. products.js.coffee) again in this situation. Then, the javascript based html form elements cannot be shown properly as they should be (because $(".checkbox").iCheck({...}) does not get executed).

How can I resolve this problem?

1 Answer 1

1

This could be a turbolinks problem. Look at the jquery-turbolinks gem, or try the following:

ready = ->

  ...your coffeescript goes here...

$(document).ready(ready)
$(document).on('page:load', ready)

You could also try and disable turbolinks to see if it is, in fact, the issue.

Sign up to request clarification or add additional context in comments.

1 Comment

I just found out my problem is because of Paloma Gem. But your answer is still completely "Correct" as according to my question.

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.