Use bikeshare to get around? Make sure there are always docks where you’re going, and bikes when you’re leaving, with
I recently started on a new project with the intention of becoming familiar with Rails 4. The site itself is very simple: it consists of only three resources, and index page that shows a random unviewed resource, a form for the public to submit new data, and an admin controller to approve or reject public submissions.
I came across this bootstrap + jquery + validate demo and liked its simplicity and I didn’t want to reinvent the wheel. So, although I’ve historically preferred to use LESS CSS, Skeleton CSS, and various icon sets, I decided this time to give Twitter Bootstrap a real try – something I’ve done in the past, but have since avoided due to its now too-familiar look and feel and enormous size.
The instructions on the site are simple:
jquery-validation-rails to your Gemfile and run
Add the following to your
//= require jquery.validate //= require jquery.validate.additional-methods
Simple, right? Well,
bundle install threw no errors, but loading any page did:
couldn’t find the file jquery.validate …
I had a hunch that the gem was simply not compatible with Rails 4. I did some digging but had no success, and after banging my head against the wall decided to investigate how the Rails 4 asset pipeline differs from that of Rails 3. I came across this little nugget:
In Rails 4.0, precompiling assets no longer automatically copies non-JS/CSS assets from vendor/assets and lib/assets. Rails application and engine developers should put these assets in app/assets or configure config.assets.precompile.
Sure enough, the jquery-validation-rails gem, stored in
/usr/lib/ruby/gems/1.9.1/gems/, was placing all its assets in
vendor/assets. I tried moving the assets around, and changing the include paths to look for them, and got it to work. But, knowing that any time I ran
bundle update things could break, I decided instead to just directly grab the jquery validation js and throw it into my site’s
vendor/assets/ directory instead.
This was addressed a few weeks ago and looks like it’s all fixed. Thanks for the update, Lasitha!