application.css file not being loaded from browser cache - ruby-on-rails

Website is running on Puma production server.
Every time I go to another page, the application.css file is also downloaded every time. But the application.js is loaded from cache successfully.

From rails official document.
<%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => "reload" %>

Related

JSON Parser Error Unexpected Token Error Rails

I recently cloned my Rails app, which was developed on Linux, to my Windows OS. There were a few errors, and I managed to fix most of them except this one. This error pops up when I try to access my page locally:
JSON::ParserError
419: unexpected token at ''
This is the code in question:
<head>
<title>DemoApp</title>
<%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %>
<%= javascript_include_tag "application", "data-turbolinks-track" => true %>
<%= javascript_include_tag "ckeditor/ckeditor.js" %>
<%= csrf_meta_tags %>
I researched and couldn't find a straightforward solution to this. I had previously changed my runtimes.rb to 'UTF-8' so that it will run in Windows.
Any help is much appreciated.
It could be because of a BOM or a tabulation space, it happens to me when I try to paste inside Vim.

Rails 5: CSS will not link to html

I'm new to rails and trying to link main.css.scss to index.html.erb file in views/main.
My css file is located in app/assets/stylesheets. This is default, I did not change anything.
So in my index.html.erb file I added the following:
<%= stylesheet_link_tag "main" %>
This throwed an error which advised me to include ".css" at the end of "main". I added ".css" and ".css.scss" to the end of main. The main page loads, but without the css file.
What is the correct way to link css in rails 5?
Read the api docs here. It will help you to understand how you can link css in rails.
Also take a look at Samuel's answer. He explained it really well.
It's very simple. If you don't want to use default application.css and application.js, then create new files, like in your case main:
app/assets/stylesheets/main.scss
app/assets/javascripts/main.js
Then in your layout include those files:
<!DOCTYPE html>
<html>
<head>
<title>Foobar</title>
<%= stylesheet_link_tag 'main', media: 'all', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'main', 'data-turbolinks-track' => true %>
<%= csrf_meta_tags %>
</head>
And add those files to assets.rb:
Rails.application.config.assets.precompile += %w( main.scss main.js)
And restart the server.

RoR tutorial (Michael Hartl) URI::InvalidURIError

I am following the RoR tutorial by Michael Hartl. Currently on chapter 3. My problem is that I don't get the view I see at https://www.railstutorial.org/book/static_pages#fig-raw_home_view.
Instead I'm seeing a
The URL I'm trying to enter is: "localhost:3000/static_pages/help".
The application.html.erb looks like this:
<!DOCTYPE html>
<html>
<head>
<title>SampleApp</title>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
<%= csrf_meta_tags %>
</head>
<body>
<%= yield %>
</body>
</html>
I'm still a rookie so really don't know what to do.
You have a problem with your app's name. To the right of Rails.root in your image, you can see that your app's name is:
sample_app]
Rails.root is the path to your application's directory, and it's used as the base path for locating all the files in your project.
The Rails.root is used in the url marked bad URI. The url is illegal because urls can only contain certain characters, and a bracket isn't one of them.
Your web browser is trying to request a css file that is specified in the application layout, and rails converts the request url to a local file url using the Rails.root. Unfortunately, Rails doesn't even bother looking for the file--instead Rails stops when it sees an illegal character in the url and throws an error.

Bootstrap Gem Installation Issue

I have added the bootstrap-sass gem and have installed the bundle. I have gone to github and think I have followed the directions correctly to finish the install for ruby on rails. It doesn't appear to be making a difference however on my local site - no font/formatting changes have been made, even after the install.
I am using a PC, https://github.com/findingtheway/pin
Change your app/views/layouts/application.html.erb to this:
<head>
<title>Pin</title>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
<%= csrf_meta_tags %>
</head>
Rails uses application by default you have default which is why bootstrap is not loading.

Errno::ENOENT No such file or directory Rails 4

Showing "/Users/Christian/Desktop/sample_app/app/views/layouts/application.html.erb" where line #5 raised:
No such file or directory - /Users/Christian/Desktop/vendor/assets
(in /Users/Christian/Desktop/sample_app/app/assets/stylesheets/custom.css.scss)
<html>
<head>
<title><%= full_title(yield(:title)) %></title>
<%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %>
<%= javascript_include_tag "application", "data-turbolinks-track" => true %>
<%= csrf_meta_tags %>
<%= render 'layouts/shim' %>`
I was developing on linux ubuntu and it works fine there, I copied the folder to my mac and it no longer works. custom.css.scss is in the correct location
The problem is on line number 5 :
<%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %>`
Change sass-rails version to 4.0.3 and leave the rest as it is. Remove Gemfile.lock when necessary, and then:
$ bundle update
$ bundle install
Finally, don't forget to restart your rails server!
In your Gemfile change the sass-rails version to 4.0.3. Get rid of a version number for sprockets. Delete the Gemfile.lock. Run the bundle install again

Resources