Sprockets::FileNotFound when trying to include a jQuery gem - ruby-on-rails

I'm trying to use https://github.com/linjunpop/jquery-tablesorter-rails to sort my tables. I'm running into issues when trying to include the CSS:
/*
* = require jquery-tablesorter/blue
*/
Error message:
Sprockets::FileNotFound: couldn't find file 'jquery-tablesorter/blue'
I do see the Gem being loaded in the config path:
1.9.3p194 :008 > Rails.application.config.assets.paths.each { |x| puts x }
.rvm/gems/ruby-1.9.3-p194/gems/jquery-tablesorter-1.0.5/vendor/assets/images
.rvm/gems/ruby-1.9.3-p194/gems/jquery-tablesorter-1.0.5/vendor/assets/javascripts
.rvm/gems/ruby-1.9.3-p194/gems/jquery-tablesorter-1.0.5/vendor/assets/stylesheets
Any idea what the issue could be?

Can't reproduce. Usually when this kind of things happen to me is because of forgetting to restart the dev server after bundling a new gem. Sprockets tries to build or resolve a new set of assets, but the loaded environment is the same as before, so the additional asset can't be found.

The corret path is:
*= require jquery-tablesorter/theme.blue

I've updated Tablesorter to use themes in version 2.4+, so the blue theme file has been renamed and moved to a different directory.
I don't know much about Ruby, or that repo but you might want to get Tablesorter v2.3.11 until that repo has been updated (see this issue in that repo).

I'm seeing the path you're requiring as a directory; the error message seems to indicate that it's failing to find a file. Have you tried
*= require jquery-tablesorter/blue/*
instead?

Related

A way to display a list of public assets

(Been looking for this for ages over internet...).
Been working with very old npm packages recently and seems that they cannot be loaded properly within Rails-6 (I know I could create a question by each cases, but I'd like to learn to handle this myself since every time it is for a different reason).
I'd like (as for debugs and in development mode only) to display the list of available all assets, including js, css, images, and anything else available at public level (the client could load). So it should be a set of compiled assets ?
Similarly to http://localhost:3000/rails/mailers like http://localhost:3000/rails/assets ?
Displaying the list of all available assets (prior compilation, also for debug intents) could also be great.
This might do what you want:
Rails.application.assets.each_file do | pathname |
# ...
end
This will enumerate every file of which Sprockets is aware. You can run that at rails c or build a simple controller to dump the list into a view if you prefer. For more information, see https://stackoverflow.com/a/11005361.
If you're not using Sprockets (e.g. a newer Webpacker-based application) then, obviously, you'll need a different solution.
You can run rails assets:reveal and see all the available assets:
$ rails assets:reveal
application.js
application.js.map
application.css
application.scss
...
To view the full path, use rails assets:reveal:full:
$ rails assets:reveal:full
/home/{REDACTED}/app/assets/builds/application.js
/home/{REDACTED}/app/assets/builds/application.js.map
/home/{REDACTED}/app/assets/builds/application.css
/home/{REDACTED}/app/assets/stylesheets/application.scss
...

ngAnimate in Rails, I just want to hook it up

why is it always so hard to hook things up to AngularJS?!?!?!
here's the error I get for anything new I try to install to Angularjs:
Error: [$injector:unpr] http://errors.angularjs.org/1.2.8/$injector/unpr?p0=%24%24asyncCallbackProvider%20%3C-%20%24%24asyncCallback%20%3C-%20%24animate%20%3C-%20%24compile
Everything works fine when I don't include ngAnimate in:
WriterSarah = angular.module("WriterSarah", ["restangular", "ui.router", "ngAnimate" ])
I put my angular-animate.min.js file in the SAME place that I do all my other Angularjs files, and I required it in my Application.js file in the SAME way that I did for restangular and ui.router
I restarted my server a bunch of times as well. what am I missing here?
The problem is likely that the Angular version does not match to the angular-animate version. Check to see if the angular versions are the same between both files.

Evergreen + jasmine-jquery

I want to make use of the new json fixtures ability of jasmine-jquery, but can't get it to work. I have a Rails 3.2 app with evergreen for JS testing. As the readme of https://github.com/velesin/jasmine-jquery said, putting the jasmine-jquery.js inside the spec/javascripts/helpers dir would load jasmine-jquery automatically.
I put jasmine-jquery (and other libraries like jasmine-ajax) into
spec/javascripts/helpers dir (so they are automatically loaded) and
fixtures into spec/javascripts/fixtures dir.
But it doesn't. I tried to load the file inside the spec_helper.js, but the require only points to the public dir.
I also found this answer: https://groups.google.com/forum/?fromgroups=#!topic/ruby-evergreen/0Tma5RKqZB8
But the solutions aren't working in my case.
So, where can I tell evergreen / jasmine to load the jasmine-jquery.js file, so that I can use the loadFixtures methods...?

rails console error require './example_user'

I'm using the railstutorial at http://ruby.railstutorial.org/chapters/rails-flavored-ruby#sec:a_user_class
I've been told to type require './example_user' but... I get this error
LoadError: cannot load such file -- example_user
from /Users/snook3/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:251:in require'
and then further and further errors
I imagine that I'm not linking correctly to that folder, can anyone let me know where I should be linking too?
Yes, just move the file to the actual root directoy. Doing mv example_user.rb* / should do it.
Also, don't worry if after requiring the file, you get a return of "true" instead of ["User"].
You can use
Rails.root
to get your current Rails project root.
So
require Rails.root + 'path_to_example_user'
would load the file.
You can also try the reload! command, which will reload the whole Rails environment.
The file should end with .rb:
require './example_user' #will not work
require './example_user.rb' #will work
To rename the file, use the following command line (not in the rails console):
mv example_user example_user.rb
try using absolute path for the file... something like this:
require '/Users/snook3/my/project/folder/example_user.rb'
No need to specify the full path, simply append .rb to the filename: require './example_user.rb'.
I had this exact same problem, but not being very familiar with Unix I can only explain it like this.
1) I created the example_user.rb file in Sublime Text 2 and saved it to the application root folder.
2) The "require" wasn't working for me, just like the OP. Even though I could see the file there in the folder.
3) However, opening up a Terminal window, navigating to the application root, and entering "dir", I could then see that the filename had a "/ " before it!? Not sure how/why that happened, or why it wasn't visible in Explorer (or whatever the Unix equivalent of that is called--Nautilus?).
4) After renaming the file from within Terminal, it all worked. But would love an explanation of what went wrong if this makes sense to any of you Unix/Rails folks.
Try
touch example_user.rb
in Unix terminal. And then add code to this file.
The tutorial tells you to "create the file example_user.rb in your application root directory". I mistakenly initially put it in the app folder and got the same error message.
If you instead move the file into your project root directory, then require './example_user' will work.

How to put capybara output html to a specific folder?

When I use the "Show me the page" step, with Capybara / Cucumber, can I control where the files get output? I can't seem to find the config for this, and my google fu is failing me.
Right now it appears that by default they go to the root of my rails folder and clutter up things there.
There is indeed a config option that allows you to specify where to output the files:
Capybara.save_and_open_page_path
I believe it was added in the latest version (0.3.9)
In your env.rb file you can do something like:
Capybara.save_and_open_page_path = '/Users/jsboulanger/my-rails-project/tmp'
In Capybara 2.10, Capybara::save_and_open_page= is deprecated. Instead, call Capybara::save_path=
Nice. Thanks for this.
To be really neat about it I added the config line to config/environments/test.rb, since you generally only use capybara in test, and that works fine.
Since there's a bunch of subfolders in tmp/ I used:
Capybara.save_and_open_page_path = 'tmp/capybara'
and created that folder.

Resources