Skip to content
Mirv edited this page Mar 22, 2017 · 1 revision

Cocoon trouble shooting stuff ...

break down of document...

  • List of common issues for Cocoon
    • List of subclasses of these problems - for the intermediate users to jump ahead
  • How to work the process to trouble shoot for Cocoon

...end the break down, begin the document

Jquery problems

How to recognize

  • You can see buttons/tabs/links, but click something & nothing happens
  • Not everything you programmed is happening
  • Other Jquery stuff (bootstrap, widgets, etc) stop working
  • You might or might not see your assets in the web console
  • If you try logging something to the web browser console, it doesn't show up

Classes of Jquery issues

  • Rails asset pipe line - assets not loading (in webconsole)

    • lack of javascript_include_tag
    • javascript_include_tag not side the header or header tag not closed
    • lack of //= . at the end of the application.js
    • automatically generated .coffee files in the assets directory, conflicting with .js files if you don't use coffeescript
  • Non-responsive / Conflicts

    • Duplicates of the Jquery source files
      • Slow loads
      • Sudden flashes or effects
      • Most of the time there is no sign, your cocoon fields will appear, but none of the effects will work

Strong_params Gotcha

How to recognize

  • You used a rails version 2 or 3 guide (pre-2014 date normally)
  • Your Jquery stuff (dynamic forms and effects, etc) work, looks pretty & return in console

How to trouble shoot

  • Check if it's a loading issue
  • Web Console elements, do assets you named show up?
  • First we need to decide if it's a loading issue - Open the web browser console & check elements for your js file names ... saw the cocoon was loaded under the "elements" section

  • Opened the /layouts/application.html.erb file & ensured there was only one javascript_include_tag.

  • Also that the javascript_include_tag was in the <head> tag & that the head tag is properly closed with </head>

  • Look for other non-essential or extra service loading files

  • Checked the /app/assets/javascript folder for the application.js file,

  • Check that there's no .coffee files (rails autos them if certain gems are installed)

  • Check inside the application.js file ...

  • Check order of your /app/assets/javascript/application.js files being loaded to ensure //= require_tree . at bottom of list

  • absolutely must be at the bottom or you're going to have issues including all the files manually into the application.js.

  • Additionally, all files must have the required, //= in front of them.

  • Ensure no extra scripts being loaded in the views, I use grep -r 'script' /app & check any spot that shows up

  • If the asset asset is loading, we know it's either a conflict or poorly written code

  • Insert a piece of test code in the console so when the $.document or the turbolinks finished loading to see if it's poor code (Try this one: https://ihatetomatoes.net/jquery-for-complete-beginners-console-log-scrolltop/)

  • I have it report to console a string ("Page -- Loaded") using the techniques above

  • If it doesn't load, it's a conflict with other java files, if it loads, it's just your code needs to be fixed

  • I pull all the entries from the application.js except a test.js file which contains the page loaded described above

  • At this point it should work if everything before it passed ... if not you might have corrupt files ... you should go into application.html.erb & use javascript_include_tag to include a CDN version of Jquery (link to include here: https://code.jquery.com/) & how to use it here: https://jquery.com/download/#using-jquery-with-a-cdn

  • Assuming the test.js works ...

  • first, in your app/assets/javascript/application.js, at the bottom of the file up the //= . & save it ...

  • You should re-add your js files to the app/assets/javascript one at a time, testing each time by refreshing the ...

  • webpage, possibly restarting the server after copying the file in to the application.js

  • If you are not using a CDN you will need to be doing a rake or rails assets like shown below based on version ...

  • For versions before Rails 5, use rake assets:clean & the rake assets:precompile

  • For Rails 3 & 4 use rails assets:clean & the rails assets:precompile ... I believe Rails 1 & 2 didn't use asset pipeline.

Asset Pipeline is described offically here ... http://guides.rubyonrails.org/asset_pipeline.html

Clone this wiki locally