Sprockets::Rails::Helper::AssetNotPrecompiled in ResqueWeb - ruby-on-rails

I've been trying to fix this for about two days but I'm getting no where. I'm trying to get the resque-web page to show but I keep running into the error
Sprockets::Rails::Helper::AssetNotPrecompiled in ResqueWeb::Overview#show
Message shown
ActionView::Template::Error (resque_web/plugins/resque_scheduler/application.css):
12: file_path = "#{p.name.underscore.downcase}/application.css"
13: if (Rails.application.assets && Rails.application.assets.find_asset(file_path)) ||
14: (Rails.application.assets_manifest && Rails.application.assets_manifest.assets[file_path])
15: stylesheet_link_tag "#{p.name.underscore.downcase}/application"
16: end
17: end.join("\n").html_safe
18: %>
what is being called from the stack
def raise_unless_precompiled_asset(path)
raise Helper::AssetNotPrecompiled.new(path) if #check_precompiled_asset && !precompiled?(path)
end
end
end
gem versions
resque (2.0.0)
resque-multi-job-forks (0.5.1)
resque-scheduler (4.4.0)
resque-web (0.0.12)
sprockets (4.0.2, 3.7.2)
sprockets-rails (3.2.2)
routes.rb
require "resque_web"
require 'resque-scheduler'
require 'resque/scheduler/server'
Rails.application.routes.draw do
mount ResqueWeb::Engine => "/resque_web"
root to: "pages#home"
.
.
.
end
Ideally it will be 'admin/resque_web' for production purposes.
I've tried this fix by "bitterloa" https://github.com/resque/resque-web/issues/106 because my file structure is set the same using webpacker
I've looked and the development.rb to check that debugging is false
I've recompiled my assets after destroying them using sprock-rails rails assets:clobber
Any ideas where I can look or if anyone else has run into this problem lend a hand please.
Run commands from terminal shows that resque is running and accepting schedule jobs from my scheduler.yml file I just can't get the css for it to work.
If you need any more info let me know.
Thanks

resque comes with a built-in server. You do not need resque-web and it seems it is not maintained (last commit was on 2018).
Let's try this:
gem 'resque', require: 'resque/server'
# routes.rb
mount Resque::Server.new, :at => "admin/resque"
Make sure you allow just admins to access to that page in production. For that you could read about Route Constraints to do something like:
constraints IsResqueAllowed do
mount Resque::Server.new, :at => "admin/resque"
end
class IsResqueAllowed
def self.matches?(request)
# use the request to do something
end
end
More information about securing the route here.

If you want to use resque-web then in order to fix this issue you will need to add in assets.rb:
Rails.application.config.assets.precompile += %w[idle lifebuoy poll rails working].map { |img| "resque_web/#{img}.png" }
Rails.application.config.assets.precompile += %w[resque_web/application.css]
Rails.application.config.assets.precompile += %w[resque_web/application.js]
Subsequently you will need to run: rake assets:precompile
And the issue should be fixed.

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

Cannot connect to the model by rails sitemap_generator gem?

I want to use this gem (sitemap_generator)
sitemap_generator
To create my sitemap xml file for my site.
So i create sitemap.rb inside config folder
Then i put this code inside
require 'rubygems'
require 'sitemap_generator'
SitemapGenerator::Sitemap.default_host = 'https://xxxx.com/'
SitemapGenerator::Sitemap.create do
# add '/home', :changefreq => 'daily', :priority => 0.9
# add '/contact_us', :changefreq => 'weekly'
add '/'
add '/signup'
add '/login'
Activity.find_each do |activity|
add activity_show_path(activity.id), :lastmod => activity.created_at
end
end
SitemapGenerator::Sitemap.ping_search_engines # Not needed if you use the rake tasks
But when i run
ruby config/sitemap.rb
I always got this
uninitialized constant Activity (NameError)
So how can i fixed this
(I guess the problem from the model)
Thanks!
I always run it through the rake task, try this:
rake sitemap:refresh:no_ping
It's possible the rake task does the magic to make the application code available when that's running.
Update: probably a duplicate of Rails sitemap_generator Uninitialized Constant? (sorry I should have looked first)

Gem not initializing within my app

I have come across an issue with my gem, it seems that it is not initializing when starting the rails server, if i run this script in the console i can access the model classes, however when i start the rails server i get 'uninitialized constant errors'
require "blogModels/version"
module BlogModels
Gem.find_files("models/*.rb").each do |f|
filename = File.basename(f, '.*')
class_name_symbol = filename.classify.to_sym
autoload class_name_symbol, "models/#{filename}"
end
end
my gemfile
gem 'mygem', :git => "pathtogem"
afterwhich i ran bundle
Would there be a reason as to why it is not loading when i am retrieving it from git?
Thanks

Cron job in ruby on rails not work

I followed the railscast http://railscasts.com/episodes/164-cron-in-ruby but I cant seem to make it worked.
I have schedule.rb in my config.
I wished to refresh my Database.count everyday in my homepage.
I cannot find the deploy.rb in my folder. Where is it?
For testing purpose, I changed it to every 2 seconds.
[schedule.rb]
every '2 * * * *' do
rake "pages_controller:home"
end
[pages_controller.rb]
class PagesController < ApplicationController
def home
#title = "Home"
#companies = Company.find(:all, :limit => 20)
#count = Company.count
end
I have put
gem 'whenever', :require => false
in my gemfile. What have gone missing?
I have used cron job but i run it as rake task please you can try it
every 3.minutes do
set :environment, 'development'
rake "daily",:output => {:error => 'error.log', :standard => 'cron.log'}
end
And my task is like
require 'rubygems'
task :daily => :environment do
puts "i am fine"
# do your code
end
If cron job run fine then there will be nothing in cron.log.Otherwise it will show you if
any error occurs and this file will be generate in your app root directory.
try it..
So... Couple things.
You need a Capfile and a config/deploy.rb to deploy your code using Capistrano and Whenver. You get this by running capify . ... You should most likely watch the railscast on capistrano deployment
Whenever is using configured like:
schedule.rb
every 1.day, :at => '4:30 am' do
runner 'Rails.cache.clear'
end
I really don't think rake "pages_controller:home is going to work unless this is something you've already created elsewhere. I'm further assuming you are caching this page, and that's why you need to refresh the cache.
Finally, you're setting your environment to development, which makes me think you are not deploying this, but instead just wanting to reset the cached home page... So just run rake cache:clear

Heroku uninitialized constant Rails:Initializer (NameError) (noWWW Rack Middleware)

I'm running Cedar stack on Heroku, rails 3.1.3.
using:
http://trevorturk.com/2009/11/05/no-www-rack-middleware/
When I push to Heroku, I get:
app[web.1]: => Rails 3.1.3 application starting in production on http://0.0.0.0:15548
app[web.1]: => Call with -d to detach
app[web.1]: => Ctrl-C to shutdown server
app[web.1]: Exiting
app[web.1]: /app/config/environment.rb:7:in `<top (required)>': uninitialized constant Rails::Initializer (NameError)
Anyone have any ideas whats going on?
Here's my environment.rb (AppName = proper name for my app. i.e. thats not the issue)
# Load the rails application
require File.expand_path('../application', __FILE__)
# Initialize the rails application
AppName::Application.initialize!
Rails::Initializer.run do |config|
config.middleware.use "NoWWW" if RAILS_ENV == 'production'
end
lib/no_www.rb:
class NoWWW
STARTS_WITH_WWW = /^www\./i
def initialize(app)
#app = app
end
def call(env)
if env['HTTP_HOST'] =~ STARTS_WITH_WWW
[301, { 'Location' => Rack::Request.new(env).url.sub(/www\./i, '') }, ['Redirecting...']]
else
#app.call(env)
end
end
end
I had the same problem using Rails 3.1. I ended up using this post. It appears to be more involved than other solutions but there are really only two steps.
Make sure to change yoursite.com in the code. I overlooked this and had to rush another deployment after the fix.
The error you're receiving is telling you that you're referencing an old version of Rails. Rails 3.1 initializes quite a bit differently than it did 2 years ago when that article was written. In particular, the problem is with the now deprecated Rails::Initializer in this block:
Rails::Initializer.run do |config|
config.middleware.use "NoWWW" if RAILS_ENV == 'production'
end
You might have more luck with rack-rewrite. Regardless, check out the official Rails documentation for a good breakdown of current configuration and initialization.
It looks like your middleware file is not being loaded. Place your middleware class, no_www.rb in app/middleware. This way it will be auto-loaded by Rails. Then add your config statement to application.rb, near the end.
...
# Configure Rack middleware
config.middleware.use 'NoWWW'
end
end
I had this issue; I know it's a late answer but I wanted to add this for whoever needed it.
Make sure that your OmniauthCallbacksController IS IN A users FOLDER. "app/controllers/users/omniauth_callbacks_controller.rb"

Resources