computer_smile
computer_smile

Reputation: 2227

jQuery plugin Rails not loading

I've had this problem before and I spent two full weekends trying to figure out and understand the issue. The same problem continues to arise. Hopefully, I can identify what is exactly going on in this rails app.

Getting the jQuery plugin pageslide to work with my rails app.

In app/vendor/assets/javascripts is the file jquery.pageslide.js. So, I modify my application.js manifest accordingly-

//= require jquery
//= require jquery-ui
//= require jquery_ujs
//= require jquery.ui.datepicker
//= require raphael.min
//= require justgage
//= require jquery.purr
//= require best_in_place
//= require lightbox
//= require jquery.cookie
//= require jquery.joyride-2.0.3
//= require jquery.pageslide
//= require modernizr.mq
//= require_tree .

I do the same thing for the jquery.pageslide.css in app/vendor/assets/stylesheets. The application.css manifest

 *= require jquery.ui.datepicker
 *= require_self
 *= require bootstrap
 *= require front
 *= require lists
 *= require tasks
 *= require lightbox
 *= require joyride-2.0.3
 *= require jquery.pageslide
 */

Now using the plugin to slide out a modal in one of my views-

views/lists/show.html.erb-

<a href="#modal123" class="second_thing">Link text</a>
<div id="modal123" style="display:none">
    <h2>Modal</h2>
    <p>And all the stuff.</p>
    <a href="javascript:$.pageslide.close()">Close</a>
</div>

javascripts/lists.js.coffee-

$ ->
  $("a.second_thing").pageslide({ direction: "left", modal: true });

My initital checklist-

-No warnings or errors from the console. -The css and js pageslide files are found in the pages' source. - Making sure the DOM/jQuery is loaded before calling pageslide in javscripts/lists.js.coffee -The order of my manifest file doesn't seem to indicate that the lists.js.coffee is being executed before pageslide.js is loaded

It looks like I'm missing some additional checks to make sure this works?

Other notes- In development env, other jQuery plugin working (joyride but calling it in show.html.erb page with script tags), I have this line config.assets.initialize_on_precompile = false to appease devise in application.rb.

I'm stumped, what else should I be checking for?

Upvotes: 0

Views: 529

Answers (1)

computer_smile
computer_smile

Reputation: 2227

Ok I got it working thanks to @muttonlamb's comment and rereading the asset pipeline section on rails guides.

I added this line in my show.html.erb file because pageslide requires the source file to be included within the body tag and the way I had it initially it was only being loaded in the head.

<%= javascript_include_tag "jquery.pageslide" %>

NOTE: I also explicitly added jquery.pageslide under app/assets/javascripts to make the above reference.

This doesn't seem the most performance friendly so I will gladly mark a better answer to achieve the above.

Upvotes: 2

Related Questions