Cannot auto-compile scss files in ruby on rails using sass-rails - ruby-on-rails

I'm new to Ruby on Rails and SO. I have a task to make CSS changes in an existing project built on Ruby on Rails. I searched online and found that .scss files auto compile to .css. So I started making changes in .scss files. But, when I edit and make changes in the files, it is not getting reflected on the browser. I tried restarting the rails server using command rails s, clearing browser cache/cookies, deleted assets folder inside public still, the changes are not getting reflected on the browser.
Finally, I deleted the tmp folder and restarted the rails server. Only then was I able to see my changes on the browser. I want to know if there is an easier way to see the changes directly on saving the scss file?
PS: I have development environment set up and my Gemfile has rails of version '>= 5.0.0.1' and I have sass-rails to '~> 5.0'.
Please let me know if any additional information is required

It was a problem with WSL. we have just shifted ROR project folder outside of 'C:\Users\username\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\rootfs\home' and it worked.

Related

How do I import ruby gems assets to project? [duplicate]

I'm trying to wrap the bootstrap-sass gem inside another gem (let's call it my-engine). Along the way, I'm building a small Rails application to test things out. As a first step, I wanted to make sure I could get bootstrap-sass working directly in my Rails application. The Gemfile for the Rails app looks like this:
gem 'bootstrap-sass', '3.3.1.0'
gem 'my-engine, path: "~/dev/my-engine"
This works fine. The bootstrap assets are loaded into my Rails application and everything looks good. Now, I want to take bootstrap-sass out of my Rails app and let it load through my-engine. So, my Rails application Gemfile now looks like:
gem 'my-engine, path: "~/dev/my-engine"
The .gemspec for my-engine has:
spec.add_runtime_dependency 'bootstrap-sass', '3.3.1.0'
I can re-bundle the my-engine gem with no problems. I can re-bundle the Rails application with no problems. However, when I refresh the page of the Rails app, I get the following error:
File to import not found or unreadable: bootstrap-sprockets.
That break occurs when sprockets is trying to build the application.css file. Sometimes this will pass and I'll get a different error about missing the bootstrap.js javascript file when the application.js is being built.
Why is this happening? I'm wondering if it has something to with the fact that I'm developing the gems locally and haven't published them, although I'm not sure why that would affect bootstrap-sass which is published. I'm using bundler 1.5.3.
Make sure 'bootstrap-sass' is required in your engine. One sensible place to do this is in your lib/my-engine.rb file:
require 'bootstrap-sass'
Adding the bootstrap-sass gem as a runtime dependency in the .gemspec isn't enough when you're trying to wrap gems.
As you want to use more and more scss/js/coffeescript libraries, you may want to consider moving to bower vs gemfiles as the source for bootstrap-sass-official. We use bower-rails for rake tasks and auto-configuration. It's a really lite config/rake task layer over standard bower.
Addressing your answer, bootstrap problems via the gem was one of the reasons I switched our engine over to just bower assets. We now import bootstrap-sass-official and have full control, note however that for sass files you will need to import the longer path to the source file, i.e. in our engine _application.scss:
# our custom variable overrides
#import 'overrides/variables';
#import 'bootstrap-sass-official/assets/stylesheets/bootstrap-sprockets';
#import 'bootstrap-sass-official/assets/stylesheets/bootstrap';
NOTE: if you want your app sass variables to override engine and sass variables, make sure your engine has _application.scss not application.scss, the leading underscore is critical for variable context/scope.
Thinking ahead, you may need to ignore bower transitive dependencies as we did.
(i.e. some dependencies may use 'bootstrap' while others use 'bootstrap-sass-official' etc)
We use it like this in our .bowerrc such as the following:
{
"ignoredDependencies": [
"bootstrap",
"bootstrap-sass",
"bootstrap-sass-official"
]
}
In conclusion
We have been using this for several months with success. bower-rails will install the dependencies in /vendor/assets and if referenced in your engine, you won't need to reference them at all in your application project. It has been fast and easy to maintain/add/update libraries and know exactly how files are included.

Vendored assets in a Rails engine not loading when used as a Gem

Im writing an isolated Rails Engine which has it's own javascript in app/assets which in turn loads a bunch of dependencies that are kept in the engine's vendor/assets.
I've been using the dummy app in the test folder for development and everything has worked as I expect.
If I package the engine up as a gem and install it into a separate rails app, when I try to access the engine in a browser I get the Sprockets::FileNotFound exception couldn't find file.
If I fire up the console and have a look at Rails.application.config.assets.paths it includes mygem/app/assets but not mygem/vendor/assets.
This is where it gets weird. If I change the rails app's Gemfile and load the engine directly from a path, I don't have these problems. I can view my engine in browser without any Sprockets issues. Loading up the console and looking at Rails.application.config.assets.paths shows both path/to/mygem/app/assets AND path/to/mygem/vendor/assets.
I don't get this. Why would I get different behaviour if the engine is being loaded as a packaged gem or directly from a path?
Answering my own question. School-boy error, nothing to do with the asset pipeline, everything to do with adding the vendor path to the gemspec configuration.
s.files = Dir['{app,config,db,lib,vendor}/**/*', 'README.md', 'LICENSE.md']

Use gem as library in Rails 4

Is there a way to use a gem as a library in Rails 4?
I have tried putting in a gem folder after cloning into lib folder but this doesn't seem to be working
You can set local path to gem in your Gemfile if I clearly understood the problem.
# Gemfile
gem 'my_perfect_gem', path: './path/to/my_perfect_gem'
I think it's better to set local gem location only in development and test environments, so wrap this line in a group. Unfortunately you should restart your rails server any time you've updated the gem.
May be there is a better approach such as using your gem as a part of application in lib folder – Auto-loading lib files in Rails 4

Rails locations - where do I locate a gem

In Rails -
Where should I locate Gems? I downloaded bootstrap and it's working, as well as a sample Rails app, separately, but I want them to work together. There is a bootstrapped rails gem (http://rubygems.org/gems/bootstrapped-rails) which I downloaded, but I'm unsure as to where I should locate it. Under models?
And how do I make sure I am referring to it? I need to add something in controller as well?
Again, more an answer to the question in the title than to what was intended by the questioner but you can use
bundle show <gemname>
To locate the directory where a gem is installed.
As Dfr mentioned: https://github.com/seyhunak/twitter-bootstrap-rails
Twitter bootstrap isn't anything more than (mostly) a collection of css/js/image files.
Add this to your gemfile
gem "twitter-bootstrap-rails"
run
bundle install
run for simple css
rails generate bootstrap:install static
It should place relevant js and css files into your application.js and application.css files accordingly. (Read more about asset pipeline)
To get you started, in the gem's link under section - "Generating layouts and views", you can see rake tasks to generate sample layouts.
e.g.
rails g bootstrap:layout application fixed
You should now have a twitter-bootstraped application.html.erb file under views/layouts.
To answer the question in the title, you can locate your gems by running gem env in the console. That will give you the specific information about your "RubyGems Environment:" When you run gem install some_gem_name it will add this gem to your system.
However, what it sounds like your trying to do is add a gem to your app. If this is the case you add gems to a rails application's Gemfile.
So using your example, you'd locate your Gemfile and add the following:
gem "bootstrapped-rails", "~> 2.0.8.5"
Once that's done, you run bundle install in your terminal.
I find that a good resource for basic rails information can be found here: http://guides.rubyonrails.org/getting_started.html
The tutorial is short and it will give you a great starting point.

rails ajax_pagination couldn't find file 'history'

I have installed ajax_pagination gem from https://github.com/ronalchn/ajax_pagination
When I restart my server i get this message
couldn't find file 'history'
(in
/Users/user/.rvm/gems/ruby-1.9.3-p362/gems/ajax_pagination-0.6.3/lib/assets/javascripts/ajax_pagination.js.erb:3)
and inserted calls in assets manifests, rails version is 3.2.8
I had tried installing a history gem ( https://github.com/philostler/historyjs-rails ) or adding history.js to assets but nothing helps
Thanks for any help!
I had the same issue, all you need to do is:
Add gem 'jquery-historyjs' to your Gemfile,
Run bundle install
Then rails generate historyjs:install
This appears to be a bug in the jquery-historyjs gem, which ajax_pagination depends on. You may want to report an issue on their github repo.
As a work-around, you could create a blank history.js file in app/assets/javascripts and try bringing in historyjs-rails.

Resources