Hide RoutingErrors from production.log for images - ruby-on-rails

How to hide from production.log all routing errors to users uploaded files like this
ActionController::RoutingError (No route matches [GET] "/uploads/*

An easy way will be to use the Silencer gem: https://github.com/stve/silencer
Something like this should work:
config.middleware.swap Rails::Rack::Logger, Silencer::Logger, :silence => [%r{^/uploads/}]

Related

No route matches [GET] "/resque/overview" when using resque in production with passenger

I'm using resque for background processing, the route /resque works fine in development, but in production (using passenger) it doesn't, the log/production.log shows the error:
ActionController::RoutingError (No route matches [GET] "/resque/overview")
when I run the command
rails routes | grep resque
it shows:
/resque
#<Resque::Server app_file="/var/www/webroot/ROOT/vendor/bundle/ruby/2.7.0/gems/resque-2.0.0/lib/resque/server.rb">
my Gemfile:
gem 'resque'
my config/initializers/resque.rb
require 'resque/server' # this is needed for resque web UI
redis_url = {
development: 'localhost:6379',
production: Redis.new(url: 'redis://{user}:{password}/{host_url}:6379/0')
}
rails_env = Rails.env.to_sym || 'development'
Resque.redis = redis_url[rails_env.to_sym]
my routes
authenticated :user, -> user { user.admin? } do
mount Resque::Server.new, :at => "/resque"
end
I will answer my question,
The issue was the following line
authenticated :user, -> user { user.admin? } do
Which seems to not work with my installed devise version 4.7.3
Once I get rid of it, the /resque route started to work! but I needed a way to restrict viewing that route for admin users only, so here is what I did,
in the config/initializers/resque.rb I added this:
require 'resque/server' # this is needed for resque web UI
class SecureResqueServer < Resque::Server
before do
redirect '/' unless request.env['warden'].user&.admin?
end
end
Then in routes.rb my /resque route becomes:
mount SecureResqueServer.new, :at => "/resque"
The above class and route are from Resque, Devise and admin authentication
That solved my issue... not sure but it seems that this issue is related to this:
https://github.com/heartcombo/devise/issues/5019

rake routes shows routes.. but I got ActionController::RoutingError(no route error)

rake routes
this is my routes file
but when I make request '/', I got error
F, [2020-02-12T04:57:06.400949 #21830] FATAL -- : [eac71eea-131f-4edc-8c7f-7681d02c6824] ActionController::RoutingError (No route matches [GET] "/"):
it's working in my local.
I set :server_mode in secrets.yml, and It worked.
but, in production, it's not working.
I had to make routes in routes.rb not admin_routes.rb.
What should I do?

Rails does not route to root 'welcome.index'

ruby -v = 2.1.6p336
rails -v = 4.2.1
MySQL --version = 14.14
New to programming and Rails. Going through tutorials.
did rails generate controller welcome index.
Rails Server - localhost:3000 shows Welcome aboard page.
Change config/routes.rb file... un-comment out root 'welcome#index' (got rid of the #. (line 8)
Rails Server - localhost:3000 shows error.
----------copied from localhost:3000------------------------------------------
ExecJS::ProgramError in Welcome#index
Showing c:/row/dev/readit/app/views/layouts/application.html.erb where line #6 raised:
TypeError: Object doesn't support this property or method
Rails.root: c:/row/dev/readit
Application Trace | Framework Trace | Full Trace
app/views/layouts/application.html.erb:6:in `_app_views_layouts_application_html_erb___173287605_49138164'
commented the root 'welcome#index' out again, and I have the Welcome Aboard page back.
If I execute localhost:3000/index
I get a routing error. No route matches [GET] "/index"
I have:
controllers/welcome_controller.rb
views/welcome/index.html.erb
this is the start of the config/routes.rb file -----------------
Rails.application.routes.draw do
get 'welcome/index'
# The priority is based upon order of creation: first created -> highest priority.
# See how all your routes lay out with "rake routes".
# You can have the root of your site routed with "root"
root 'welcome#index'
How do I get the config/routes.rb file to display the views/welcome/index.html.erb file?
Does this have anything to do with the MySQL socket I'm suppose to put in the config/database.yml ? Because I don't what to put there.
It looks like there is an error at line 6 on "application.html.erb". If you want to create a hyperlink from that page to the "root" page, you should use the following view helper:
<%= link_to "Home", root_path %>
When the page is rendered and you check the HTML code using the Chrome's inspector, you will see that above code is converted to:
Home
In your app/views/layouts/application.html.erb, try changing the line:
<%= javascript_include_tag 'application', data-turbolinks-track => true %>
To this (removing the data-turbolinks-track => true):
<%= javascript_include_tag 'application' %>
That might fix it. You shouldn't remove the entire line as it's likely you'll need JS available in your layout at some point in the project :)
Hope it helps!
I fixed it by renaming my [It may not sound correct but it worked for me , give it a try]
app/views/layouts/application.html.erb
TO
app/views/layouts/default.html.erb
I hope it works for you as well

Rails - CKEditor - No routes matches lang/fr.js and editor.css

I'm trying to use CKeditor in production, but it always fails.
The log :
Started GET "/backend/articles/lang/fr.js?t=C6HH5UF" for 127.0.0.1 at 2013-03-12 20:52:40 +0100
ActionController::RoutingError (No route matches [GET] "/backend/articles/lang/fr.js"):
And
Started GET "/backend/articles/skins/kama/editor.css?t=C6HH5UF" for 127.0.0.1 at 2013-03-12 20:52:40 +0100
ActionController::RoutingError (No route matches [GET] "/backend/articles/skins/kama/editor.css"):
In my prodcution.rb :
config.serve_static_assets = true
# Compress JavaScripts and CSS
config.assets.compress = true
# Don't fallback to assets pipeline if a precompiled asset is missed
config.assets.compile = true
I've tried explicitly adding the files according to this question => How to get ckeditor resources to compile and load in Rails 3.1 asset pipeline
config.assets.precompile += [ /.*config\.js/, /.*fr.js/, /.*editor.css/ ]
But it fails... It means that textareas are not displayed.
Does somebody have an idea ?
THanks for your help.
this might help you, try to add like this:
in your production.rb:
config.assets.precompile += ['ckeditor/skins/kama/editor.css', 'ckeditor/lang/fr.js', 'ckeditor/skins/kama/editor.css']
and in the layout, add this line in the HEAD tag of html:
<script type="text/javascript">
var CKEDITOR_BASEPATH = '/assets/ckeditor/';
</script>

Carrierwave seems to be working as expected but photos won't show because of routingerror in ruby on rails

I've just completed my user photo album feature in my application and images upload to public/uploads folder, but he images aren't showing and this is coming up in my logs:
Started GET "/uploads/photo/image/11/thumb_admguk.png" for 127.0.0.1 at 2012-01-19 00:42:26 +0000
ActionController::RoutingError (No route matches [GET] "/uploads/photo/image/11/thumb_admguk.png"):
Would very much appreciate help figuring out this issue.
Kind regards
This caused my issue:
config.serve_static_assets = false
This was my solution:
config.serve_static_assets = true
If you use Paperclip, try to add this in your Model:
has_attached_file :your_attribute_name,
:url => "/uploads/photo/image/:id/:basename.:extension",
:path => ":rails_root/public/uploads/photo/image/:id/:basename.:extension"
...

Resources