I'm stumped. I have a vanilla install of Rails 5 running within docker yet I'm constantly getting this error:
Request ran for longer than 5000ms
All I've done so far was generate a new controller with docker-compose run website rails g controller pages.
So far, if I remove (very important) lines from layouts/application.html.erb, I can get the page to load:
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
But I loose all my default styling (bootstrap) and any potential javascript files I wish to load later in life, which I do not consider to be a fix.
Anyone else run into this problem and know how to fix it?
#JimmyBaker answered in the comments
Try setting config.assets.debug to false
Inside config/development.rb
config.assets.debug = false
Having this set to false will cause all CSS & JS to be bundled into application.css or application.js More on assets.debug
Related
After installing the device gem, I encountered an error. How can i fix this:
Webpacker can't find application in /home/grkmdgn06/Desktop/my5_homework/public/packs/manifest.json. Possible causes:
1. You want to set webpacker.yml value of compile to true for your environment
unless you are using the `webpack -w` or the webpack-dev-server.
2. webpack has not yet re-run to reflect updates.
3. You have misconfigured Webpacker's config/webpacker.yml file.
4. Your webpack configuration is not creating a manifest.
Your manifest contains:
{
}
Extracted source (around line #9):
...
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %> # error line
...
perhaps your node.js is out of date
try this:
sudo npm install n -g
sudo n stable
bundle exec rake webpacker:install
Apologies in advance if this is so basic I probbaly shouldn't post it here. I'm not even sure if the title actually describes the issue. I am just starting to look at Ruby on Rails, and am following this page to set up "my first application": http://guides.rubyonrails.org/getting_started.html
Now, when I get to the point where I add
root 'welcome#index'
Into the routes.rb file and try and access it, it all goes wrong. First I thought it was a permissions issue, but I can access the views/layouts/welcome/index.html.erb file directly in the browser.
I'm so new to this that I haven't got far enough to know what I'm looking for in troubleshooting, hence this post.
When starting the rails server, I do get what looks like errors on restart and hangup signals, but I doubt this is the problem. Output listed here just in case.
=> Booting Puma
=> Rails 5.1.2 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
*** SIGUSR2 not implemented, signal based restart unavailable!
*** SIGUSR1 not implemented, signal based restart unavailable!
*** SIGHUP not implemented, signal based logs reopening unavailable!
Puma starting in single mode...
* Version 3.9.1 (ruby 2.3.3-p222), codename: Private Caller
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://0.0.0.0:3000
Use Ctrl-C to stop
Loading the root page gives the following server output:
Started GET "/" for 127.0.0.1 at 2017-06-28 13:17:23 +0200
Processing by WelcomeController#index as HTML
Rendering welcome/index.html.erb within layouts/application
Rendered welcome/index.html.erb within layouts/application (13.0ms)
Completed 500 Internal Server Error in 3742ms
ActionView::Template::Error (TypeError: Object doesn't support this property or method):
5:
6: <%= csrf_meta_tags %>
7:
8: <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
9: <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
10:
11: </head>
app/views/layouts/application.html.erb:8:in `_app_views_layouts_application_html_erb___750167210_57076860'
It kind of looks to me as though it does load the index page, but then something else triggers and it's redirected to a page that doesn't work. The content of the page it's directed to (views/layouts/application.html.erb) is:
<!DOCTYPE html>
<html>
<head>
<title>Blog</title>
<%= csrf_meta_tags %>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
</head>
<body>
<%= yield %>
</body>
</html>
Content of routes.rb for reference is:
Rails.application.routes.draw do
get 'welcome/index'
root 'welcome#index'
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
end
Add below lines in /assets/stylesheets/application.css
/*
* This is a manifest file that'll be compiled into application.css, which will include all the files
* listed below.
*
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
*
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
* compiled file so the styles you add here take precedence over styles defined in any styles
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new
* file per style scope.
*
*= require_tree .
*= require_self
*/
As a bit of pre-text, I am used to Rails 2 but started building a sample app to get used to Rails 4 and I am having a nightmare with Sprockets and the asset pipeline even after reading the official guide and every question I can find on SO.
My css and js are included like so in my main view file:
<head>
...
<%= stylesheet_link_tag "application", media: "all" %>
<%= stylesheet_link_tag "style-responsive", media: "all" %>
<%= stylesheet_link_tag params[:controller], :media => "all" if stylesheet_exists?(params[:controller]) %>
<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<%= javascript_include_tag 'html5shiv' %>
<%= javascript_include_tag 'respond.min' %>
<![endif]-->
...
</head>
....
<%= javascript_include_tag "jquery-1.10.2.min" %>
<%= javascript_include_tag "jquery-ui-1.9.2.custom.min" %>
<%= javascript_include_tag "jquery-migrate-1.2.1.min" %>
<%= javascript_include_tag "bootstrap.min" %>
<%= javascript_include_tag "modernizr.min" %>
<%= javascript_include_tag params[:controller] if javascript_exists?(params[:controller]) %>
stylesheet_exists? and javascript_exists? are helper functions as I only want to include certain files when they are needed as opposed to the rest which are needed on every page.
The first error is:
Asset filtered out and will not be served: add `Rails.application.config.assets.precompile += %w( style-responsive.css )` to `config/initializers/assets.rb` and restart your server
If I then add that to assets.rb and restart, it moves on and the issue is repeated for every stylesheet_link_tag and javascript_include_tag in my view.
I could live with that even if it doesn't seem right but this comes crashing down when the interpreter gets to
<%= javascript_include_tag params[:controller] %>
Would I then need to also include every js file that I create for each controller? This seems wrong that I would have to constantly update the file whenever I create a new asset file.
In my application.css.erb I only have
*= require_self.
but I do have the old fashioned CSS #import for some stylesheets:
#import url(http://fonts.googleapis.com/css?family=Open+Sans:400,300,300italic,400italic,600,600italic,700,700italic,800,800italic);
#import url('bootstrap.min.css');
#import url('bootstrap-reset.css');
#import url('jquery-ui-1.10.3.css');
#import url('<%= asset_path 'css/font-awesome.min.css' %>');
#import url('custom-ico-fonts.css');
but all of these seem to work fine and don't need to be mentioned in assets.rb.
I have no requires set in application.js.
TLDR I think I am using Sprockets and the Asset Pipeline incorrectly, could someone please point out what it is I'm doing wrong and point me in the right direction?
I read about some similar issues to do with the sprocket-rails gem version 2.2.3 but I have 2.2.4 installed which is meant to have fixed any problems that existed in the previous version.
Rails 4.2.1
ruby 2.1.0p0 (2013-12-25 revision 44422) [x86_64-linux]
sprockets (3.0.1, 2.12.3)
sprockets-rails (2.2.4)
Sprockets wants to compact everything into a single file and minify it, so typically the pattern is to include all your javascript/stylesheets in the application manifests. There are plenty of good reasons for this pattern.
Since it appears you have removed the = require_tree . lines, this is not happening automatically and thus Rails wants to know about each individual file you plan to include separately via the assets.precompile configuration option. If requiring the entire directory is too aggressive, break your assets into subfolders and be more explicit about what you want to include.
Sprockets is relatively brittle and fighting against it is an uphill battle. So in both cases (JS/CSS), you should include it all and use selectors that are smart enough to scope page-specific styles or JS to that page.
That said, sometimes we cannot avoid having certain assets omitted from global inclusion. If you need to exclude a specific file from your manifest use a stub directive and include it separately with the HTML tag helpers.
Also note that you can have additional manifests (other files that include = require ... directives of their own) ... so long as you add those to the assets.precompile list.
The combination of stub and require directives and additional manifests should give you enough flexibility to organize your assets to your liking and make adding additional assets frictionless.
An application error constantly occurs:
2014-11-26T06:45:10.349830+00:00 app[web.1]: ActionController::RoutingError (No route matches [GET] "/stylesheets/application.css"):
In my application.html I have:
<%= stylesheet_link_tag "application" %>
In my production.rb, because heroku is not serving and the application should serve static assets I have:
config.serve_static_assets = true
config.assets.compile = true
On the live site I have:
<link href="/assets/application-da7e0e08bb87fbae6f1225fa189fab8e.css" media="screen" rel="stylesheet" type="text/css" />
The url
mysite/assets/application-da7e0e08bb87fbae6f1225fa189fab8e.css
returns a result.
The url
mysite/assets/application.css
also returns a result.
Everything is working fine, but there is this error message in the log and I can not understand why. Who requests /stylesheets/application.css and why and how to stop this error from occurring.
Rails is "3.2.16"
There should be two problems:
1) add %<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>>
2) It looks like you have added assets precompiled file in your git repo. Ideally, it shouldn't be there since heroku can this for you whenever you push it.
To fix this, you have to do this
git rm -r public/assets/
add public/assets/** in your .gitignore file
git add .
git commit -am "allow heroku auto assets precompilation"
5.git push heroku master
I have an app written in Rails 3.1 and I need completely to change the CSS styles in the project. I bought a template, deleted the current CSS styles from assets/stylesheets (including application.css) and pushed there the new CSS files.
Further I modified the stylesheet_link_tag with the names of new CSS files.
Then, when I open browser with the app, refresh the app - there are not loaded the new files. When I take a look at the generated source code, there are still the paths to the old CSS files.
I have read that probably would help me rake assets:precompile - but this is kind of impractical to every time, when I make a change in CSS files to run this command (which takes like 2 minutes I guess).
Is there any better way to handle it?
Thank you
*EDIT: * In the <head> tag:
<%= javascript_include_tag "jquery" %>
<%= javascript_include_tag "jquery-ui" %>
<%= stylesheet_link_tag "application", :media => "all" %>
<%= stylesheet_link_tag "http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/redmond/jquery-ui.css" %>
<%= javascript_include_tag "bootstrap" %>
<%= javascript_include_tag "application" %>
Could it be just a browser cache? Try to force the reload (ctrl+f5).
Try to delete <your_app>/tmp/cache and restart the server.
Unless you decide to switch off the asset pipeline (which I don't recommend because it's actually pretty good), you're going to have to build yourself a new application.css. If you don't to that, your CSS files won't be recognized at all.
Just think of it as an inventory of every one of your CSS files. You can use this as a template.
/*
*= require cssfile1
*= require cssfile2
*/
And then, revert the stylesheet link tag to its original form in your layout. Inside your `application.html.erb', remove any reference to your CSS files and use this instead:
<%= stylesheet_link_tag "application", :media => "all" %>
Yup, importing new asset files into a rails application isn't a straightforward proposition.