Firstly, sorry if this is a basic question - I'm pretty new to rails.
I've created a very basic rails application using the standard scaffold.
I have two CSS files - one global (global.css) and one that is page
specific (in this example, ammos.css). The global CSS has most of the
CSS design and the local file has code for the UI element positioning on
that page.
I have the following code in the head section of the
application.html.erb file (under the "views" folder):
Then I have the following code in the "_form.html.erb" file that was
generated when I generated the scaffold.
<% content_for :head do %>
<link rel="stylesheet" type="text/css"
href="/stylesheets/ammos_new.css">
<% end %>
The CSS settings show properly if I use the URL for the "/ammos/new"
page directly in the browser. However, when I go to the "/ammos" page
and then click the "New" link, the local CSS settings do not show up.
The page behaves as if they do not exist.
Would anyone know why this occurs and how it can be avoided?
+1 on Ganesh’s reply, but wondering why you are not simply using “<%= stylesheet_link_tag “application”, media: “all” %>”? That way all stylesheets are picked up as long as you have them in the app/assets/stylesheets folder. Simply remove the stylesheets you don’t want.
Have you tried using your browser’s inspector to check whether the stylesheets are loading correctly and what differences (if any) exist between your 2 cases? Does inspecting an element that should have one of these extra rules show that those rules have been overridden or that they are missing entirely?