This has hit me twice and I cannot get past it this time. The first time, I pushed/pulled from github and got webrick to boot up. This a.m. I attempted to do the same thing. I do recall restarting my dev machine yesterday which would cause webrick to restart.
Background, this is my first 'production' app and I'm using danielkehoe's starter template on github that uses cucumber, rails3 and devise. I've chosen Twitter-bootstrap as my CSS generator.
Hunting on the web suggested bundle update, rebooting webrick. Of those google results that directly mirror mine, there was no resolution posted. I have branched out and installed rails 3.2 but that made no difference.
Here is the Exception:
couldn't find file 'bootstrap'
(in /Users/sam/apps/keriakut/app/assets/stylesheets/application.css.scss:6)
Extracted source (around line #10):
9: <meta name="author" content="">
10: <%= stylesheet_link_tag "application", :media => "all" %>
11: <%= javascript_include_tag "application" %>
My trace:
app/views/layouts/application.html.erb:10:in
`_app_views_layouts_application_html_erb___2282066720260402873_2178181480'
I would have thought that caching is not used in development mode and doesn't that file look like it's cached?
It seems there is no bootstrap document for twitter-bootstrap, but it seems to be incorporated into sass, scss files? This is my inexperience showing.
Based on another stackoverflow answer I added: gem "twitter-bootstrap-rails", "~> 2.0rc0" into my Gemfile but after updating, the results are not the same. I want to understand what I'm doing wrong with my environment to keep this coming up, sam
I think you're including too many unrelated details. Sounds like you have /*= require twitter/bootstrap or similar in your application.css.scss manifest and it can't be found. Bootstrap doesn't come with Rails or Sass. You can either drop it manually into your stylesheets directory from the Bootstrap website and require it or you can use one of the gems out there that contains it.
Since you're using the twitter-bootstrap-rails gem, the documentation says that you install it by running:
rails generate bootstrap:install
That will probably unpack the bootstrap css files from the gem into your stylesheets directory.
And your application.css.scss should contain:
*= require twitter/bootstrap
Related
I am working with a Rails 5.2 application
Locally I added a new image to app/assets/images/my-file-name.jpg
and then in my .erb file I reference it using
<%= image_tag "my-file-name.jpg" %>
Then when I deploy to Heroku I run the following steps locally
rake assets:clobber <!-- this destroys the public/assets folder as expected
RAILS_ENV=production bundle exec rake assets:precompile this creates a new public/assets folder but now each of the files within the assets folder have a hash after their name. So my file my-file-name.jpg has become my-file-name-{BigLongCacheBustingHashHere}.jpg
git push staging <-- Deploy to my staging environment and check that the log says assets compiling -- all good.
Check staging environment if the image is being served and I notice that the app cannot find my image because my <%= image_tag my-file-name.jpg %> is still producing a static html link WITHOUT the hash. It looks like this <img src="my-file-name.jpg"> when I believe it should be producing a tag that looks like <img src="my-file-name-{BigLongCashBustingHashHere}.jpg"
Why do you think the <%= image_tag %> is not producing production friendly urls?
I can see that it is working elsewhere in the app so not sure where I am going wrong.
OMG I lost hours of my life on this. Rails assets does not like .jpeg extensions and will flat out ignore them in production. So I just changed the file name to my-file-name.jpg and now Rails is happy
We have a Rails 5 application and recently updated Sprockets from the 3.x series to 4.0.2. Now Rails can't find an asset (CSS file) belonging to a vendored gem. Note that the gem is an engine and the asset is called from a template inside the engine.
The asset is referenced inside a file at vendor/gems/our_vendored_gem/app/views/layouts/ like this:
<%= stylesheet_link_tag "our_vendored_gem/application", :media => "all" %>
The file is at vendor/gems/our_vendored_gem/app/assets/stylesheets/our_vendored_gem/application.css
Then we get the error Sprockets::Rails::Helper::AssetNotPrecompiled in OurVendoredGem::Mocks#index.
Our app/assets/config/manifest.js looks like this:
//= link_tree ../images
//= link_directory ../javascripts .js
//= link_directory ../stylesheets .css
I tried adding
//= link_tree ../../../vendor/gems/our_vendored_gem/app/assets/stylesheets/ .css
...but that did not help. The vendored gem has a manifest file of its own but it is unclear to me if Sprockets is already reading it, or if it needs to be called somewhere.
What needs to happen to make this file available to Rails again?
After some digging, I found this issue comment which explains that a Rails engine should have its own manifest file; that file can then be included in the application manifest like this:
//= link my_engine
This will find a manifest file at my_engine/app/assets/config/my_engine.js and add those directives to those in the application manifest.
I am new to Rails 5.0.0.1
I followed the guidelines in http://guides.rubyonrails.org/asset_pipeline.html#controller-specific-assets:
You can also opt to include controller specific stylesheets and JavaScript files only in their respective controllers using the following:
<%= javascript_include_tag params[:controller] %> or <%= stylesheet_link_tag params[:controller] %>
When doing this, ensure you are not using the require_tree directive, as that will result in your assets being included more than once.
I generated some scaffolds (which also generated the assets -- .coffee and .scss)
When I do rails s and access one of the scaffold's main page, it generated an error:
Asset was not declared to be precompiled in production.
Add Rails.application.config.assets.precompile += %w( myscaffold.css ) to config/initializers/assets.rb and restart your server
I do as it said, and it worked, but is there any other way to simplify this process?
I wish that I can generate some other scaffolds or controllers with their assets without doing any more concern of adding new lines inside the config/initializers/assets.rb.
I will receive any other alternatives too.
you just try this..
check your Gemfile gem 'sprockets-rails', '2.3.3'
And bundle install
Navigate files
config/initializers/assets.rb
Then add
Rails.application.config.assets.precompile += %w( your_file_name.scss )
Restart server
I am creating a Redmine plugin and would like to use Haml for the view templates. There is an existing plugin which has Haml views (ekanban) and it does not contain any special code to get Haml working other then having you add require 'haml' to your main application's Gemfile.
So here is what happens -- the templating system loads the .html.haml file correctly but renders the HAML markup (like it was rendering ERB).
I've tried to insert the require 'haml' at various intervals to no avail. I've even tried manually trying to activate Haml.init_rails(...) as suggested in this SO question. I've tried inserting that in a few places, tried it in a Rails.configuration.to_prepare block in the plugins' init.rb file. I've tried telling the Gemfile to not require 'haml' and attempting to do it during plugin load to no avail. What gives?
The view template had Textile in it and I did not notice because the markup for <h2> is similar (h2. vs. %h2). Including gem 'haml_rails' in the plugin's Gemfile is sufficient with no extra code.
Read carefully Installation instruction for this gem :)
Add "gem 'haml'" to your #{RAILS_ROOT}/Gemfile
I can't agree with this strategy: plugin can't change Redmine core! Any Redmine plugin can have own gems (defined in own Gemfile) - so I think you can create Gemfile in your plugin, run bundle install from the Redmine root and I believe you will manage to use Haml
I'm migrating an app to Rails 3. The following - which I've seen recommended in a few places - does not work:
<%= javascript_include_tag :defaults %>
In my case, it expands to this:
<script src="/assets/defaults.js" type="text/javascript"></script>
... which results in a 404. As I understand it, the :defaults is not supposed to include a file called "defaults.js"; it's supposed to include a few essential things like prototype.js and application.js.
Note that in my case, the following works fine. It's just that I'd rather use the official recommended way, if possible:
<%= javascript_include_tag :prototype %>
<%= javascript_include_tag :application %>
I'm running Rails 3.2.8 with ruby 1.9.3.
I do not have the following line in my config/application.rb (in any form). To migrate to Rails 3, I created a new Rails 3 application, and used that application.rb as a starting point:
config.action_view.javascript_expansions[:defaults] = %w(foo.js bar.js)
In app/assets/javascripts, I have:
Util.js
application.js
controls.js
dragdrop.js
effects.js
prototype.js
... and a bunch of stuff specific to my application.
Since Rails 3.1, it uses assets pipeline. It means you need to change your management of assets.
You have a assets/javascripts/application.rb file which contains something like this:
//= require jquery
//= require jquery_ujs
//= require_tree .
It seems you include jquery, jquery_ujs and all other files in the javascripts repository. With the last line you don't need to do anything else in this file. You just need to include the application file in your view and rails will manage everything:
<%= javascript_include_tag "application" %>
It's exactly the same thing with stylesheets.
Then in production environment, assets (images, stylesheets, javascripts) will be compiled and minified in order to be more efficient.
I suggest you read more about here
Hope this helps
Here's a lot more about the Asset Pipeline - http://guides.rubyonrails.org/asset_pipeline.html
It's meant to make it easier to break up your Javascript into separate files for development, yet compile and minimize them in production.