Rails HTML not changing when I push to production - ruby-on-rails

I have a rails app hosted on ubuntu and served with Apache2 and Passenger. I am having issues getting changes in one of my views to actually reflect in the server. I am not talking about css but the generated html is not changing. I am at a loss for what to do. I am using turbolinks -- though im not talking about css. I have a new.js.erb file that isn't rendering on load and I have changes to a partial view that aren't rendering on restart either. All of this works in development.
production.rb
config.cache_classes = true
config.eager_load = true
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
config.serve_static_files = true
config.assets.js_compressor = :uglifier
config.assets.compile = true
config.assets.digest = true
config.log_level = :debug
config.i18n.fallbacks = true
config.active_support.deprecation = :notify
config.log_formatter = ::Logger::Formatter.new
config.active_record.dump_schema_after_migration = false
restarting the server with passenger-config restart-app
Edit 1
edit.js.erb that will not load
$("#deal_<%= escape_javascript #deal.id.to_s %>").fadeOut("slow", function() {
var div = $("<%= escape_javascript render partial: 'edit_deal', locals: {deal: #deal} %>").hide();
div.find('.save_deal_link').first().click(function(event) {
$(this).closest('form').submit();
event.preventDefault();
// Prevent link from following its href
});
$("#deal_<%= escape_javascript #deal.id.to_s %>").replaceWith(div);
div.fadeIn("slow");
});
When I attempt to access this code directly by following baseurl/accounts/2/deals/1/edit.js I get error 422 which seems to just be a standard CORS error from the log. I think a better clue to the problem is that in a partial _deal.html.erb the changes are not being reflected on the production environment.
Edit 2
I am noticing that the click handler is not firing for the link that makes the ajax request, and the production server appears to be serving the new.js.erb -- it's just changes in the view(.html.erb) are not seemingly getting served no matter how many times i upload the views folder

I changed the location of the partial from /accounts/_deal.html.erb to /application/_deal.html.erb and forgot to remove the old one on production.

Related

How to turn off Rails caching during development

I'm on Rails 5.2.2 and I'm building a web app that uses some static HTML, CSS, and JavaScript that I'm serving from inside of the public directory. Much of the time when I update a file it doesn't update in my browser when I refresh, but if I go into private browsing it works -- until it caches again and then I need to open a new private window.
How can I turn off caching for file in the public folder? Or if it's easier, how can I turn off all caching during development?
This is what my development.rb looks like. I tried commenting out the entire if Rails.root.join('tmp', 'caching-dev.txt').exist? block but that didn't do anything.
I'm also open to installing a gem to solve this if it can't be fixed with a setting.
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the web server when you make code changes.
config.cache_classes = false
# Do not eager load code on boot.
config.eager_load = false
# Show full error reports.
config.consider_all_requests_local = true
config.file_watcher = ActiveSupport::FileUpdateChecker
# Enable/disable caching. By default caching is disabled.
# Run rails dev:cache to toggle caching.
if Rails.root.join('tmp', 'caching-dev.txt').exist?
config.action_controller.perform_caching = true
config.cache_store = :memory_store
config.public_file_server.headers = {
'Cache-Control' => "public, max-age=#{2.days.to_i}"
}
else
config.action_controller.perform_caching = false
config.cache_store = :null_store
end
# Store uploaded files on the local file system (see config/storage.yml for options)
config.active_storage.service = :local
# Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = false
config.action_mailer.perform_caching = false
# Print deprecation notices to the Rails logger.
config.active_support.deprecation = :log
# Raise an error on page load if there are pending migrations.
config.active_record.migration_error = :page_load
# Highlight code that triggered database queries in logs.
config.active_record.verbose_query_logs = true
# Add devide default mailer url
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
# Raises error for missing translations
# config.action_view.raise_on_missing_translations = true
# Use an evented file watcher to asynchronously detect changes in source code,
# routes, locales, etc. This feature depends on the listen gem.
config.file_watcher = ActiveSupport::EventedFileUpdateChecker
end
It's not rails who caches, it's your browser.
Either you explicitly set
config.public_file_server.headers = {
'Cache-Control' => "no-cache"
}
(and clean your browser cache, who has all old and valid versions of your files), or you disable browser cache completely.

How can I speed up Rails development server?

I am working on Rails 4.2 & Angular 1.4.8 as the front-end. This is my development.rb file:
Rails.application.configure do
config.cache_classes = false
config.eager_load = false
config.action_controller.perform_caching = false
config.action_mailer.raise_delivery_errors = false
config.active_support.deprecation = :log
config.active_record.migration_error = :page_load
config.assets.debug = true
config.assets.raise_runtime_errors = true
config.action_mailer.delivery_method = :letter_opener_web
config.action_mailer.default_url_options = {host: "localhost:3000"}
config.consider_all_requests_local = false
end
I know that by disabling assets.debug I can really speed this up, but I need to have my assets refreshed when I refresh the page. I am doing full stack so I can't precompile assets all the time.
I recently started using guard with guard-rails - do I have any chance ?
I suspect that compiling all assets every time after file changed.
if you require angularjs libs and other libs in to application.js try to create a separate file for libraries and application
See also: Rails 3.1 is very slow in development-mode because of assets, what to do?

Heroku push incomplete

I have a rails app that works perfectly in localhost, but last time I pushed it to Heroku the "About" and "Contact" sections seems like incomplete upload or something, here is the link to the website https://damp-inlet-9409.herokuapp.com, and yes, I re-pushed like 3 times and still the same result
Update:
I think the problem is from development.rb or production.rb, here you got them:
Production.rb
Rails.application.configure do
config.cache_classes = true
config.eager_load = true
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present?
config.assets.js_compressor = :uglifier
config.assets.compile = true
config.assets.digest = true
config.log_level = :debug
config.i18n.fallbacks = true
config.active_support.deprecation = :notify
config.log_formatter = ::Logger::Formatter.new
config.active_record.dump_schema_after_migration = false
end
Development.rb
Rails.application.configure do
config.cache_classes = false
config.eager_load = false
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
config.action_mailer.raise_delivery_errors = false
config.active_support.deprecation = :log
config.active_record.migration_error = :page_load
config.assets.debug = true
config.assets.digest = true
config.assets.raise_runtime_errors = true
end
There are several potentialities with your issue.
Firstly, you're getting a rails error, which means that at the base level (IE Heroku database etc), the app should be working okay.
The main problem for many Heroku apps is that they either don't have a database, which would yield the Heroku "Application Error":
For future reference, this error means that you have an issue with how Heroku is running your app (typically that you don't have a db or something).
Since you have a rails error, it means that the problem is likely an undeclared variable, or missing conditional login etc.
--
To fix the issue, you need to check the Heroku logs:
This will give you a specific readout of the problem that's preventing the app from running. You'll then either be better placed to give us the details of said error, or fix the problem yourself.

Assets url Rails 4.1 and Heroku

Something always seems to go wrong when deploying an app to heroku, today its my images not being rendered.
I ran
rake assets:precompile RAILS_ENV=produciton
committed changes and pushed to heroku
In my view for example i have
<%= image_tag('/assets/logo.png') %>
but the image is not being rendered because its looking for logo.png as opposed to
logo-321321327454547676576586876.png
which was generated when running the precompile.. I think im missing an option in my production.rb file somwhere
Rails.application.configure do
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
config.serve_static_assets = false
config.assets.js_compressor = :uglifier
config.assets.compile = false
config.assets.digest = true
config.assets.version = '1.0'
config.log_level = :info
config.active_support.deprecation = :notify
config.log_formatter = ::Logger::Formatter.new
config.active_record.dump_schema_after_migration = false
end
How do i get the app to look for the generated image url created when precompiling? something simple Im guessing
I am going to use an S3 bucket to serve these in the future but am interested in getting it working with Heroku on its own
Thanks
After reading the api docs in more detail and taking Baloo's advice the answer is really simple, just a syntax issue with my path declarations
If your image is under assets just use
<%= image_tag('image.ext') %>
and if its in a sub directory then use
<%= image_tag('sub-dir/image.ext') %>
Hope this helps someone else

Image showing as blank in Rails 3.1 on Production (Heroku)

I recently updated my Rails to 3.1.
Here's a part where I added:
<%= asset_path('logo_symbol.png') %>
This renders /assets/logo_symbol.png which works perfectly fine in development environment. However, when i push the code to production on heroku, it shows a broken image, with the url: assets/logo_symbol-135ddc8db2c9b59f032bed7db520137a.png. I am guessing the new name is for the reason of some optimization.
It is however interesting to note that when I go to the assets/logo_symbol-135ddc8db2c9b59f032bed7db520137a.png url on production, I see a blank page, but when I change that url to anything random, like adding numbers to it, it shows a page not found. So clearly it is finding something on that url. It also shows a blank page when I go to /assets/logo_symbol.png directly on production/heroku.
If this is any help, heroku does not precompile successfully when I push the code and heroku's documentation says that there is currently no work around for that issue.
Any help in this will be greatly appreciated.
My guess is that it has something to do with some configuration related to environments. I am attaching contents of my application.rb, development.rb and production.rb files
here are the contents of my production.rb file
# Settings specified here will take precedence over those in config/application.rb
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the webserver when you make code changes.
config.cache_classes = false
# Log error messages when you accidentally call methods on nil.
config.whiny_nils = true
# Show full error reports and disable caching
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
# Don't care if the mailer can't send
#config.action_mailer.default_url_options = { :host => 'localhost:3000' }
#config.action_mailer.default_url_options = { :host => 'localhost:3000' }
config.action_mailer.delivery_method = :smtp
# Print deprecation notices to the Rails logger
config.active_support.deprecation = :log
# Only use best-standards-support built into browsers
config.action_dispatch.best_standards_support = :builtin
# Do not compress assets
config.assets.compress = false
# Expands the lines which load the assets
config.assets.debug = true
end
module ActiveAdmin
class Reloader
def attach!
end
end
end
and here are the contents of my development.rb file
# Settings specified here will take precedence over those in config/application.rb
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the webserver when you make code changes.
config.cache_classes = false
# Log error messages when you accidentally call methods on nil.
config.whiny_nils = true
# Show full error reports and disable caching
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
# Don't care if the mailer can't send
#config.action_mailer.default_url_options = { :host => 'localhost:3000' }
#config.action_mailer.default_url_options = { :host => 'localhost:3000' }
config.action_mailer.delivery_method = :smtp
# Print deprecation notices to the Rails logger
config.active_support.deprecation = :log
# Only use best-standards-support built into browsers
config.action_dispatch.best_standards_support = :builtin
# Do not compress assets
config.assets.compress = false
# Expands the lines which load the assets
config.assets.debug = true
end
module ActiveAdmin
class Reloader
def attach!
end
end
end
Here are the contents of my production.rb file
# Settings specified here will take precedence over those in config/application.rb
# The production environment is meant for finished, "live" apps.
# Code is not reloaded between requests
config.cache_classes = true
# Full error reports are disabled and caching is turned on
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
# Specifies the header that your server uses for sending files
config.action_dispatch.x_sendfile_header = "X-Sendfile"
# For nginx:
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'
# If you have no front-end server that supports something like X-Sendfile,
# just comment this out and Rails will serve the files
# See everything in the log (default is :info)
# config.log_level = :debug
# Use a different logger for distributed setups
# config.logger = SyslogLogger.new
# Use a different cache store in production
# config.cache_store = :mem_cache_store
# Disable Rails's static asset server
# In production, Apache or nginx will already do this
config.serve_static_assets = false
# Enable serving of images, stylesheets, and javascripts from an asset server
# config.action_controller.asset_host = "http://assets.example.com"
# Disable delivery errors, bad email addresses will be ignored
# config.action_mailer.raise_delivery_errors = false
#config.action_mailer.default_url_options = { :host => 'ha1.heroku.com' }
config.action_mailer.delivery_method = :smtp
# Enable threaded mode
# config.threadsafe!
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
# the I18n.default_locale when a translation can not be found)
config.i18n.fallbacks = true
# Send deprecation notices to registered listeners
config.active_support.deprecation = :notify
# Compress JavaScripts and CSS
#config.assets.compress = true
# Don't fallback to assets pipeline if a precompiled asset is missed
config.assets.compile = false
# Generate digests for assets URLs
config.assets.digest = true
# Defaults to Rails.root.join("public/assets")
# config.assets.manifest = YOUR_PATH
config.assets.js_compressor = :uglifier
config.assets.css_compressor = :scss
I have compared my config files with the rails documentation for 3.1 and seems like I have all the defaults needed. However I am still seeing no image. Any help will be much appreciated
Remove this line from production.rb:
config.action_dispatch.x_sendfile_header = "X-Sendfile"
You should also align the settings in your config files with those in section 9 of the pipeline guides.
Sendfile headers contain information for the upstream webserver of where to find the file (on the file system) to serve it. This removes the load from the backend (Rails/Sprockets). When sendfile is on the HTTP response contains no body (it is zero length) which is why you see nothing.
On heroku the nginx servers do not have access to the application filesystem, so this won't work.
See this note on the Heroku dev site re sendfile.
If you are using heroku, this document outlines the best options for using the pipeline effectively.
You need to do two things to resolve it.
First, change these two lines from false to true in production.rb file.
config.assets.compile = true
config.assets.digest = true
Second, if you've syntax like this for your images
background: url("imgo.jpg")
Change it to
background: image-url("image.jpg")
I hope it does your job.

Resources