Invalid CSS after ".": expected class name, was "." - css

When I try to load the sample user page from the rails tutorial, I get this error:
Showing
C:/Sites/rails_projects/sample_app/app/views/layouts/application.html.erb
where line #5 raised: Invalid CSS after ".": expected class name, was
"." (in
C:/Sites/rails_projects/sample_app/app/assets/stylesheets/custom.css.scss:113)
<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 can't seem to figure out what's wrong with how the code is formatted, and I don't see what "." it's referring to.

Related

Sprockets::FileNotFound; couldn't find file 'selectize.source.css'

I have recently upgraded my app from Rails 4.2.6 to Rails 5.2.3.
I followed the procedure as on Rails Guides
Now, when I try to start my development server, it starts without any error.
But when I hit the URL in the browser an error comes up which says:
Sprockets::FileNotFound in UserSessions#new
Showing /home/pranjal/source/my-app/app/views/layouts/application.html.erb where line #5 raised:
couldn't find file 'selectize.source.css'
Checked in these paths:
/home/pranjal/source/my-app/app/assets/config
/home/pranjal/source/my-app/app/assets/font-awesome
/home/pranjal/source/my-app/app/assets/fonts
/home/pranjal/source/my-app/app/assets/images
/home/pranjal/source/my-app/app/assets/javascripts
/home/pranjal/source/my-app/app/assets/stylesheets
/home/pranjal/source/my-app/vendor/assets/javascripts
/home/pranjal/source/my-app/vendor/assets/stylesheets
...
Extracted source (around line #5):
<!DOCTYPE html>
<html>
<head>
<title>My App</title>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
<%= csrf_meta_tags %>
</head>
Looks like issue of incompatibility between js and new version of rails try to use/upgrade selectize-rails gem and remove js and css files from repo (if exists).

How to add a font awesome icon to title

So I was wondering if there was a way to have a font awesome icon beside your title like this I want to use the fa fa-pencilicon. This is my code in my head:
<head>
<title><link type="fa fa-pencil" href="fa fa-pencil">Blogger</title>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
<%= csrf_meta_tags %>
</head>
All what shows up in my title is:
<link type="fa fa-pencil" href="fa fa-pencil">Blogger
In my gem file, I have added gem "font-awesome-rails" and ran bundle install.
Am I doing anything wrong? Is there a way to add the pencil icon to the title? Thanks in advance!

Use rails stylesheet_link_tag based on path || controller?

In my application layout I have this conditional which helps deciding what stylesheet to use based on existence of current_user:
<% if current_user %>
<%= stylesheet_link_tag 'application', media: 'all', id: "maincss" %>
<% else %>
<%= stylesheet_link_tag 'session', media: 'all', id: "maincss" %>
<% end %>
But how can I specify which stylesheet to use based on the url?
For example, I want to use a 'password_reset.css' file for this path
get '/set/:password_reset_token' => 'password_resets#edit'
Here is what I do in my projects:
In the layout file, add a yield method like this:
<html>
<head>
...
...
<%= yield(:head) %>
</head>
...
In any view page (.erb file) that needs a custom CSS, I would add something like this at the top of the page.
<% content_for :head do %>
<%= stylesheet_link_tag 'custom_css_filename', media: 'all' %>
<% end %>
This way stylesheet will go in the right place only for that page.
Note:
If you want to include a custom stylesheet for every single URL in your application, you should use what is suggested in the previous answer.
You can try using
<%= stylesheet_link_tag *([params[:controller], params[:action]] + (params[:id] || '').split('/')) %>
If you are okay with using password_resets.css instead of password_reset.css
Note: You may get a few unwanted link tags as well, which may result in harmless(except to logs) 404 responses

Rails 4 stylesheet_link_tag missing "text/css" in HTML

I'm using the stylesheet_link_tag in rails 4 and the outputted html is missing type='text/css'
I can't seem to find out how to add this to the stylesheet_link_tag.
You can add type option in your stylesheet_link_tag helper:
= stylesheet_link_tag 'application', type: 'text/css'
This should be automatic in your application.html.erb
<head>
<%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %>
</head>

Stylesheet_link_tag is broken, paths to files not working, can't figure out why for the life of me. Any ideas?

I'm in Rails 3.1, config,assets.enabled is true in config/application.rb
I've got these that aren't working and I can't figure out what I'm doing wrong
<%= stylesheet_link_tag 'blueprint/screen.css', :media => 'screen' %>
<%= stylesheet_link_tag 'blueprint/print.css', :media => 'print' %>
<%= stylesheet_link_tag 'custom', :media => 'screen' %>
This doesn't work either (image doesn't show with abbreviated path to image or the full path)
<%= image_tag("logo.png", :alt => "Sample App", :class => "round") %>
have you put your images in assets/images directory?

Resources