How to cache HAML files in /tmp directory? - ruby-on-rails

I'm having an issue with HAML where it is attempting to write to a read-only filesystem (on a Heroku-deployed app).
I can only write to /tmp and /log. How can I configure HAML to write files to the /tmp directory?
Thanks!
Edit:
Output of actual error
Started GET "/" for <ip> at Sun Oct 03 13:19:42 -0700 2010
Processing by WelcomeController#index as HTML
Rendered welcome/index.html.haml within layouts/application (5.6ms)
Completed in 10ms
ActionView::Template::Error (Read-only file system - /disk1/home/slugs/305306_d9977a4_8922/mnt/public/stylesheets/.permissions_check.23729009697080.19743.369932 - Heroku has a read-only filesystem. See http://docs.heroku.com/constraints#read-only-filesystem):
3: %html
4: %head
5: %title= title
6: = stylesheet_link_tag "reset", "application", "grid", :cache => "base"
7: = javascript_include_tag :defaults
8: = csrf_meta_tag
9:
app/views/layouts/application.html.haml:6:in `_app_views_layouts_application_html_haml___661334860_23729045526060_0'

Like Mark commented, I think you mean SASS, not Haml. Here's how to use git commit-hooks to precompile your SASS before deploying to heroku.
EDIT: After full error was posted
Change
= stylesheet_link_tag "reset", "application", "grid", :cache => "base"
to
= stylesheet_link_tag "reset", "application", "grid"
The caching isn't HAML, it's RAILS, and it's doing this on first read.

Related

How to properly configure the connection of .css files to .html.erb files if i have 2 controllers. Ruby on Rails

For exemple, i have something contoller_1 with index.html.irb, and i have something controller_2 with index2.html.irb, how to properly connect .css files to this html-documents. I want to connect separate files to index.html.irb (for exemple, index.css) and to index2.html.irb (for exemple, index2.css).
thank you!
You can use all stylesheets with:
<%= stylesheet_link_tag "application", :media => "all" %>
...or you may create a separate directory that will use your external stylesheet
asset::your_external_css::new_sytle
<%= stylesheet_link_tag "application", "your_external_css/new_style" %>
found in (app/views/layouts/application.html.erb)

Webpacker::Manifest::MissingEntryError in .... localhost:3000/* errors

system:
Ruby: ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-linux]
Rails: Rails 6.0.2
OS: Windows to a VM (vagrant ssh -> to ubuntu machine : Linux vagrant-ubuntu-trusty-64 3.13.0-170-generic #220-Ubuntu SMP x86_64 GNU/Linux
when I run rails server -b 0.0.0.0 I can access localhost:3000 and see the Yay! You’re on Rails!
but when I attempt to navigate to localhost:3000/say/hello
the below error comes up in browser
Browser error:
Showing /files_on_your_computer/rails6tut/demo/app/views/layouts/application.html.erb where line #9 raised:
Webpacker can't find application in /files_on_your_computer/rails6tut/demo/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):
7
8
9
10
11
12
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
</head>
<body>
Rails.root: /files_on_your_computer/rails6tut/demo
console error:
vagrant#vagrant-ubuntu-trusty-64:/files_on_your_computer/rails6tut/demo$ rails server -b 0.0.0.0 => Booting Puma
=> Rails 6.0.2 application starting in development
=> Run `rails server --help` for more startup options
Puma starting in single mode...
* Version 4.3.1 (ruby 2.6.5-p114), codename: Mysterious Traveller
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://0.0.0.0:3000
Use Ctrl-C to stop
Started GET "/say/hello" for 10.0.2.2 at 2019-12-17 17:51:09 +0000
(1.5ms) SELECT sqlite_version(*)
Processing by SayController#hello as HTML
Rendering say/hello.html.erb within layouts/application
Rendered say/hello.html.erb within layouts/application (Duration: 4.3ms | Allocations: 271)
Completed 500 Internal Server Error in 115ms (ActiveRecord: 0.0ms | Allocations: 7431)
ActionView::Template::Error (Webpacker can't find application in /files_on_your_computer/rails6tut/demo/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:
{
}
):
6: <%= csp_meta_tag %>
7:
8: <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
9: <%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
10: </head>
11:
12: <body>
app/views/layouts/application.html.erb:9
Started GET "/" for 10.0.2.2 at 2019-12-17 17:54:56 +0000
Processing by Rails::WelcomeController#index as HTML
Rendering /home/vagrant/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/railties-6.0.2/lib/rails/templates/rails/welcome/index.html.erb
Rendered /home/vagrant/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/railties-6.0.2/lib/rails/templates/rails/welcome/index.html.erb (Duration: 3.1ms | Allocations: 190)
Completed 200 OK in 6ms (Views: 5.4ms | ActiveRecord: 0.0ms | Allocations: 899)
I have seen some similar issues on heroku, but i am running this locally so I am a bit confuddled.
I am following the Agile Web Development with rails 6 book.
I faced the same issue, I was using the latest version of node v15.2.0 and switched to a lower version of node v14.8.0 and webpacker is working fine.
Reference: [https://github.com/rails/webpacker/issues/2779#issuecomment-727170370]
What I did here simply is comment out line number 9.
8:<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
9:<%#= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>

redmine upgrade to 3.4.4 not working [ActionView::Template::Error (undefined method `default_users_time_zone')]

Every thing worked fine for me with Redmine 3.3. Now I wanted to upgrade to 3.4.4 and Redmine is no longer running. I searched the internet but did not find the exact same problem. Similar problems where caused by plugins but I do not have any plugins installed. I use the Passenger Docker image of Redmine.
The logs give me the following error message:
Processing by WelcomeController#index as HTML
Current user: anonymous
Redirected to http://0.0.0.0/login?back_url=http%3A%2F%2F0.0.0.0%2F
Filter chain halted as :check_if_login_required rendered or redirected
Completed 302 Found in 60ms (ActiveRecord: 3.7ms)
App 179 stdout:
Started GET "/login?back_url=https%3A%2F%2Fredmine.mydomain.tld%2F" for 95.90.204.176 at 2018-03-14 19:10:26 +0000
Processing by AccountController#login as HTML
Parameters: {"back_url"=>"https://redmine.mydomain.tld/"}
Current user: anonymous
Rendered account/login.html.erb within layouts/base (24.1ms)
Completed 500 Internal Server Error in 219ms (ActiveRecord: 4.3ms)
ActionView::Template::Error (undefined method `default_users_time_zone' for #<Class:0x00000000055f2120>
Did you mean? default_users_hide_mail):
11: <%= favicon %>
12: <%= stylesheet_link_tag 'jquery/jquery-ui-1.11.0', 'application', 'responsive', :media => 'all' %>
13: <%= stylesheet_link_tag 'rtl', :media => 'all' if l(:direction) == 'rtl' %>
14: <%= javascript_heads %>
15: <%= heads_for_theme %>
16: <%= call_hook :view_layouts_base_html_head %>
17: <!-- page specific tags -->
app/models/user_preference.rb:44:in `initialize'
app/models/user.rb:949:in `pref'
app/helpers/application_helper.rb:1451:in `javascript_heads'
app/views/layouts/base.html.erb:14:in `_app_views_layouts_base_html_erb__2446195152155203147_36658300'
lib/redmine/sudo_mode.rb:63:in `sudo_mode'
What could that be? I need to upgrade to 3.4 because I want to use a plugin but the plugin requires version 3.4 in use.
It was my fault! I did not copy every new settings file to my mounted config directory.

Setting CSS for Launchpage that is different from Rails Application

I have two different sets of CSS files that I want to use for the same website hosted with heroku.
The first set of CSS files are the standard Twitter BootStrap CSS files converted to SASS.
The second set are custom settings for my application.
I have been able to get the look and feel right on my development server but when I upload it to heroku the output is just
<body>
<head>
</head>
</body>
Please help!
My site is configured as such:
http://imgur.com/S5Aoov1&V3RNQZ3&lSJqpCz&jdSfy82
My controlling layout file is:
doctype 5
html data-uuid=current_user.try(:id)
= render 'head'
= render 'third_party_scripts'
body class=controller_name
= render 'navbar'
= render partial: 'account/infobar'
.container
= render partial: 'flash', locals: { flash: flash }
= yield
I've duplicated this file and named it "_home.html.slim"
I've changed the contents to:
head
title = t('.title', default: 'My Winning Trade')
= stylesheet_link_tag 'home', media: 'all'
= stylesheet_link_tag 'justified-nav', media: 'all'
= stylesheet_link_tag 'http://fonts.googleapis.com/css?family=Shanti|Open+Sans:400,700,800'
= javascript_include_tag 'jquery'
= csrf_meta_tags
The CSS for my landing pages are called home & justified-nav, based on the jumbotron example provided by twitter bootstrap. http://getbootstrap.com/examples/jumbotron/
Heroku Error logs after Asset Precompile:
2013-10-04T19:48:42.124903+00:00 app[web.1]: Completed 500 Internal Server Error in 384ms
2013-10-04T19:48:42.127966+00:00 app[web.1]: 3: = stylesheet_link_tag 'home', media: 'all'
2013-10-04T19:48:42.127966+00:00 app[web.1]:
2013-10-04T19:48:42.127966+00:00 app[web.1]: 1: head
2013-10-04T19:48:42.127966+00:00 app[web.1]: app/views/layouts/sessions.html.slim:3:in `_app_views_layouts_sessions_html_slim__3803347664834042281_69939052542640'
2013-10-04T19:48:42.127966+00:00 app[web.1]: 2: title = t('.title', default: 'My Winning Trade')
2013-10-04T19:48:42.128146+00:00 app[web.1]:
2013-10-04T19:48:42.127966+00:00 app[web.1]: ActionView::Template::Error (home.css isn't precompiled):
2013-10-04T19:48:42.127966+00:00 app[web.1]: 4: = stylesheet_link_tag 'justified-nav', media: 'all'
2013-10-04T19:48:42.127966+00:00 app[web.1]: 5: = stylesheet_link_tag 'http://fonts.googleapis.com/css?family=Shanti|Open+Sans:400,700,800'
2013-10-04T19:48:42.127966+00:00 app[web.1]: 6: = javascript_include_tag 'jquery'
2013-10-04T19:48:42.127966+00:00 app[web.1]: app/views/application/_home.html.slim:3:in `_app_views_application__home_html_slim___3730913017080964654_69939053460220'
2013-10-04T19:48:42.128146+00:00 app[web.1]:
I'm not sure I completely understand what you're asking. But it sounds like:
You have a single layout file.
You want to load a single set of stylesheets in one set of views
In another set of views, you want to additionally load a second stylesheet.
Is that correct? If so, couldn't you just do something like this in your layout:
doctype 5
html data-uuid=current_user.try(:id)
= render 'head'
= render 'head_foobar' if controller_name == 'foobar'
The issue ended up being the home.css file not compiling on the heroku server side.
By changing the production.rb file setting:
from:
config.assets.compile = false
to:
config.assets.compile = true
The layout configuration that #Manishie suggested worked!
Thank you everyone!

token_error on heroku when I try to load Google API

I am using winston/google_visualr to create nice graphs to visualize statistics in my rails application.
It works fine on my locale system, but if I push it to heroku I get something like a token_error. The result is, that it shows only the Heroku page
We're sorry, but something went wrong.
My head section of application.html.erb looks like this
<head>
<title><%= full_title(yield(:title)) %></title>
<script src='http://www.google.com/jsapi'></script>
<%= stylesheet_link_tag "application", :media => "all" %>
<%= javascript_include_tag "application" %>
<%= csrf_meta_tags %>
</head>
This is the heroku log:
ActionView::Template::Error (Unexpected token name, expected punc (line: 13588, col: 3, pos: 384041)
at expect (/tmp/execjs20121119-2-qx6eku.js:977:40)
Error
at js_error (/tmp/execjs20121119-2-qx6eku.js:505:15)
at new JS_Parse_Error (/tmp/execjs20121119-2-qx6eku.js:497:22)
at token_error (/tmp/execjs20121119-2-qx6eku.js:961:17)
at expect_token (/tmp/execjs20121119-2-qx6eku.js:974:17)
at object_ (/tmp/execjs20121119-2-qx6eku.js:1365:56)
at /tmp/execjs20121119-2-qx6eku.js:1326:51
Completed 500 Internal Server Error in 4980ms
at croak (/tmp/execjs20121119-2-qx6eku.js:954:17)
at maybe_unary (/tmp/execjs20121119-2-qx6eku.js:1425:27)
at expr_ops (/tmp/execjs20121119-2-qx6eku.js:1452:32)
(in /app/app/assets/javascripts/application.js)):
6: <%= stylesheet_link_tag "application", :media => "all" %>
7: <%= javascript_include_tag "application" %>
8: <%= csrf_meta_tags %>
9: <%= render 'layouts/shim' %>
4: <title><%= full_title(yield(:title)) %></title>
5: <script src='http://www.google.com/jsapi'></script>
app/views/layouts/application.html.erb:7:in `_app_views_layouts_application_html_erb__1437494530852335371_34567960'
It looks like that the external script reference may be the reason. Do you have any idea how to implement this?
The demo implementation of the author of the googlevisualr rails extension on heroku works fine. Is there any configuration settings in heroku I need to consider?
Thanks for your help.
It took me a lot of tries but I found the issue.
The error happens if one of the included JS' has syntax errors, i.e. a missing semicolon.
In my Gemfile I didn't add version numbers to my gem '...'.
I was using the gem 'bootstrap-datepicker-rails' in version '0.6.21' for my development environment.
If you push to heroku all your gems will be installed again, with the newest available version. Since version 0.6.28 is the actual version it was installed on heroku. It may have a syntax error and it caused the above issue. So, it had nothing to do with the line
<script src='http://www.google.com/jsapi'></script>
I just corrected the line in my gemfile to the following and all was working then:
gem 'bootstrap-datepicker-rails', '0.6.21'

Resources