currently I'm trying to set up a simple app in Ruby on Rails. I've migrated the db, seeded it and am now stuck at the following error.
no implicit conversion of nil into String
Extracted source (around line #4):
1: <!--[if lt IE 9]>
2: <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
3: <![endif]-->
4: <%= stylesheet_link_tag 'blueprint/screen', :media => 'screen' %>
5: <%= stylesheet_link_tag 'blueprint/print', :media => 'print' %>
6: <%= stylesheet_link_tag 'custom', :media => 'screen' %>
It seems like the asset tags helpers are not working properly or returning nil (if that's even possible)?
I hotfixed this error by adding the following line to my application.rb:
ActionController::Base.config.relative_url_root = ''
The error is most likely due to a bug in my rails version which is 3.0.12.
Related
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).
I am trying to run a project on digital ocean's ububtu droplet. As soon as I try to install a template, I get We're sorry, but something went wrong.
If I look in my error logs, I see
I, [2016-07-30T23:49:55.921388 #9319] INFO -- : Started GET "/" for 73.160.138.220 at 2016-07-30 23:49:55 -0400
I, [2016-07-30T23:49:55.961647 #9319] INFO -- : Processing by HomeController#index as HTML
I, [2016-07-30T23:49:55.983520 #9319] INFO -- : Rendered home/index.html.erb within layouts/application (1.6ms)
I, [2016-07-30T23:49:56.628915 #9319] INFO -- : Completed 500 Internal Server Error in 667ms (ActiveRecord: 0.0ms)
F, [2016-07-30T23:49:56.631911 #9319] FATAL -- :
ActionView::Template::Error (Invalid CSS after "...ound-position: ": expected expression (e.g. 1px, bold), was "[headerposition];"):
11: <title>Christopher G. Mendla - Personal and Professional Site</title>
12:
13: <!-- From ruby begin -->
14: <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
15:
16: <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
17: <%= csrf_meta_tags %>
app/views/layouts/application.html.erb:14:in `_app_views_layouts_application_html_erb___1821054907133950454_37150040'
I had the site loaded on Digital ocean before with this template. I seem to rememebr that there was a problem with lines 14 and 16 above and I had to do something different but I can't remember what.
The portion of application.html.erb with the stylesheet tags is
<!-- From ruby begin -->
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
<%= csrf_meta_tags %>
<!-- From end begin -->
<!-- The following is added to connect the template to ruby -->
<%= javascript_include_tag "http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" %>
<%= javascript_include_tag "http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js" %>
<%= stylesheet_link_tag "style" %> <!-- From template -->
<%= stylesheet_link_tag "style.ie7" %> <!-- From template -->
<%= stylesheet_link_tag "style.responsive" %> <!-- From template -->
<%= javascript_include_tag "script.js" %> <!-- From template -->
<!-- < %= javascript_include_tag "jquery.are-you-sure" %> --> <!-- Dirty form checker -->
<%= javascript_include_tag 'defaults' %>
<%= csrf_meta_tags %> <!-- cross-site request forgery protection parameter -->
I did do rake assets:clobber and rake assets:precompile
assets.rb has
Rails.application.config.assets.compile = true #for Production
Rails.application. config.assets.precompile = ['*.js', '*.css', '*.css.erb'] #for Production
Rails.application.config.assets.precompile += %w[*.png *.jpg *.jpeg *.gif] #for Production
Rails.application.config.assets.precompile += %w(script.js)
Rails.application.config.assets.precompile += %w(script.responsive.js)
Rails.application.config.assets.precompile += %w( style.css )
Rails.application.config.assets.precompile += %w( style.responsive.css )
Rails.application.config.assets.precompile += %w( style.ie7.css )
If I change application.html.erb to simply be <%= yield %> then the site shows up without an error. I can't figure out where the error message is pointing in my css
I do see lines such as the following in style.css but I can't figure out which, if any of those lines is causing the problem
ul.art-vmenu ul a:hover:after
{
background-position: center ;
}
ul.art-vmenu ul a.active:hover:after
{
background-position: center ;
}
ul.art-vmenu ul a.active:after
{
background-position: bottom ;
}
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
I am quite new to Ruby on Rails and wanted to place my custom CSS file into the Devise (Sign Up View). I placed my global CSS into the application.js (Asset Pipeline) and placed 2 Helper functions in my
helpers/application_helper.rb
def javascript(*files)
content_for(:head_javascript) { javascript_include_tag(*files) }
end
def stylesheet(*files)
content_for(:head_stylesheet) { stylesheet_link_tag(*files) }
end
and my views/layouts/application.html.erb
<!DOCTYPE html>
<%
if (controller.controller_name == "sessions") && (controller.action_name == "new")
javascript 'theme/signup'
stylesheet 'theme/signup'
end
%>
<html>
<head>
<title>Mysite</title>
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js" type="text/javascript"></script>
<![endif]-->
<%= yield(:head_stylesheet) %>
<%= stylesheet_link_tag "application", :media => "all" %>
<%= javascript_include_tag "application" %>
<%= yield(:head_javascript) %>
<%= csrf_meta_tags %>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<%= yield %>
</body>
</html>
Then I generated the Devise Views and adjusted my twitter bootstrap form
rails generate devise:views
And now want to place my signup.css inside the Signup View, but how?
So I created the Devise Controllers, to use my helper methods:
bash <(curl -s https://raw.github.com/foohey/cdc/master/cdc.sh)
Now I am stuck, because I my helpers donĀ“t work with:
<%
if (controller.controller_name == "sessions") && (controller.action_name == "new")
javascript 'theme/signup'
stylesheet 'theme/signup'
end
%>
Is there an easy way in rails to handle custom css files? I am new to the asset pipeline concept and it is a bit confusing.
Thanks for help.
Have you heard about content_for? It is really useful for things like that. Inside you layout add:
<%= yield :head %>
inside your head tag. Then you can write the following inside the view (devise/sessions/new):
<% content_for :head do %>
javascript 'theme/signup'
stylesheet 'theme/signup'
<% end %>
This will perfectly separate your layout from single view concerns, and it should also fix the problem you're having.
You can place your custom css files in the css directory inside the public directory and inside the <head> tags of the view you want the custom css files to be you do this
<%= stylesheet_link_tag '/css/signup' %>
The signup.css will only be available to the signup view assuming that's where you place your stylesheet_link_tag
I think you want something like these:--
<% if (controller.controller_name == "sessions") && (controller.action_name == "new")%>
<%= stylesheet_link_tag "theme/signup"%>
<%= javascript_include_tag "theme/signup" %>
<% end %>
I get an error while trying to load any page:
ActionView::Template::Error (variable #fontAwesomeEotPath_iefix is undefined)
(in /app/assets/stylesheets/bootstrap_and_overrides.css.less)):
2: <html>
3: <head>
4: <title>Program</title>
5: <%= stylesheet_link_tag "application", :media => "all" %>
6: <%= javascript_include_tag "application" %>
7: <%= csrf_meta_tags %>
8: </head> app/views/layouts/application.html.erb:5:in `_app_views_layouts_application_html_erb__242882506_70513990' app/controllers/problems_controller.rb:7:in `index'
What I did before? Just run bundle update
Because of bootstrap update I will need to update bootstrap's assets:
rails g bootstrap:install -f
There are a new line in assets:
+#fontAwesomeEotPath_iefix: asset-path("fontawesome-webfont.eot#iefix");
This also happened to me. This is because, When you update your Bootrap gem, You should update Its js and less css. Do
rails g bootstrap:install -f
This will add a line to your app/assets/css/bootstrap_overrides.css.less file
like
#fontAwesomeEotPath_iefix: asset-path("fontawesome-webfont.eot#iefix");