Cant load models folder in my rake task for Sinatra project - rake-task

I have a simple rake task that requires some models.
I cant require model in my rake task.
I have tried following.
Dir.glob("../../models/*.rb").each { |r| require_relative r }
My rake task in it lib/tasks
when i do rake -T i can see my task. But when i try to run i get
uninitialized constant [ClassName]
Any help is appreciated.

Used require_relative and all was fixed. Plus following question has great answer to this problem.
You can load your whole environment in a rake task.
How do I make Rake tasks run under my Sinantra app/environment?

Related

gitlab Health Check is Unhealthy

I'm migration my gitlab to another server. the old gitlab server use postgresql and the new gitlab server use mysql.
I'm convert it with tools calld “DBConvert for MySQL & PostgreSQL”.
Database had sucess convert , and the repo files also copyd to the new gitlab server.
But my projects can't use , when click the projects it notice http code 500.
In gitlab Health check ,it notice
Migrations are pending.
To resolve this issue, run: bin/rake db:migrate RAILS_ENV=production"
And when I run this cmd , it notice "No Rakefile found"
How to proceed from there?
Make sure to execute bin/rake db:migrate RAILS_ENV=production from your GitLab-CE installation folder.
Or try from the same GitLab folder:
bundle exec rake db:migrate RAILS_ENV=production"
my src and dst gitlab version are 8.8.4 , it's the same
In that case, simply do not execute any db:migrate RAILS_ENV=production: that will avoid creating duplicate tables.
Problem is resloved , see link How to resloved "Migrations are pending. To resolve this issue, run: bin/rake db:migrate RAILS_ENV=production".

Heroku - CSS not loading on a single page but everywhere else

Sorry in advance, I know there are topics on this subject, but this is maddening! I wouldn't be as frustrated if this problem wasn't limited to just the index. The CSS loads fine all on the pages of my app except the post/index page. I should note it runs perfectly locally and I've been banging my head against this since this morning so I may have overlooked something banal and apologize in advance.
Gem file
gem 'rails_12factor', group: :production
gem 'pg', group: :production
Production.rb
config.cache_classes = true
config.serve_static_assets = true
config.assets.compile = true
config.assets.digest = true
Running the following was unsuccessful:
RAILS_ENV=production bundle exec rake assets:precompile
bundle exec rake assets:precompile
Specifying while assets to precompile in production.rb was unsuccessful
config.assets.precompile += %w( public.css public.js )
config.assets.precompile += %w( assets/stylesheets )
Also tried changing the extensions from .css to .scss and adding a new custom.scssand linking to it without success.
Link to my app and the page in question:
https://clickbait22.herokuapp.com/
Link to its Github repository:
https://github.com/4thking/clickbait
Try running...
heroku run bundle exec rake assets:precompile
heroku open
In production, you must run rake assets:precompile to serve up anything in your app/assets folder. In development mode, Rails constantly checks for updates to the files and serves them each one separately.
It is nice when you're developing, but is quite slow in production. So, to speed things up, Rails has you run a single, longer task that shrinks and combines a bunch of files in app/assets, speeding up page loading times and reducing server load.
Hope this helps you out!
UPDATE:
Whilst you said that you have tried doing the following, I want to include it for clarity regardless. Quite often it is important to precompile your assets before you push to Heroku. Inside the terminal this process would look similar to this...
rake assets:precompile
git commit -m 'Assets precompiled'
git push heroku master

How to run db:setup in Capistrano 3 and Rails 4

Just getting started with Capistrano 3, and I noticed on one of my first deploys for my_app that it was complaining about the MySQL database not existing.
DEBUG [aec39935] ActiveRecord::NoDatabaseError: Unknown database 'my_app'
Well that's expected, since this a brand new deploy to a clean server. I included the capistrano-rails gem that's meant to take care of db migrations
require 'capistrano/rails/migrations'
I'd expect it to run db:create before db:migrate so that the database is created, but looks like it doesn't.
Is there a way for me to manually add this in, or reconfigure it so that it does run it?
Thanks.
To my knowledge, you can either create a special task to do this, or just run db:setup manually once. I'd personally recommend the latter.
If you want to make a custom task, take a look at the rails/migration task as an example: https://github.com/capistrano/rails/blob/master/lib/capistrano/tasks/migrations.rake#L15

Rails looking for a databases not specified by database.yml

I recently pulled some code and ran rspec. The tests passed with no problem. When I ran "rake db:migrate" and "rake db:prepare" however, I got an issue.
Now no rspec test passes, and every failure cites the same error:
Mysql2::Error: Table 'app_test.admins' doesn't exist: SHOW FULL FIELDS FROM `admins`
The thing is, that database name is not specified anywhere in the code. In database.yml, 'app_test' is specified, with no '.admins' suffix.
Similarly, when I run rails server, I get the following error:
Mysql2::Error: Table 'app_dev.admins' doesn't exist: SHOW FULL FIELDS FROM `admins`
Only 'app_dev' is specified in yml.
The rake commands (db:migrate, db:test:prepare, db:create, db:drop, etc.) are all modifying the database.yml specified databases, it's just that Rails is looking for databases with the '.admins' suffix. Where is this '.admins' suffix coming from and how can I remove it?
app_test and app_dev are database names.
it's just that Rails is looking for databases with the '.admins'
suffix.
Actually app_test.admins and app_dev.admins are tables that rails is looking for in the two databases. Couple of approaches that I would try:
rake db:create
rake db:migrate
or
rake db:schema:load
The issue was as follows:
When I pulled the code, for whatever reason, the 'Admins' table disappeared from db/schema.rb. This table cannot be restored via rake:db:migrate because the migration that created it uses t.database_authenticatable, which has been deprecated and no longer works with the Devise gem. Because we're building on legacy code, we only run rake db:migrate on recently changed migrations, never from an empty database (for an empty database, we use rake db:schema:load).
Since the table was missing from db/schema.rb it would not be restored even if I used rake db:schema:load. To fix the issue, I had to use git reset to revert to an old version of db/schema.rb.
To fix the Devise deprecation issue so that you can run all of your migrations, go here - https://github.com/plataformatec/devise/wiki/How-To:-Upgrade-to-Devise-2.0-migration-schema-style
Is rake db:prepare a valid command? Did you try rake db:create:all?
Is it possible that your rails-settings-cached is configured to use admin table? Do you remember typing rails g settings admin?
Check in your models for a admin.rb file, or for a model that derivates from RailsSettings::CachedSettings
Check your initializers for the same gem as well

rake failure due to imagemagick

I'm seeding a development database (mysql) using rake db:seed in Rails 3. The rake task fails, stating,
Validation failed: Logo /var/folders/.../logo.png is not recognized by the 'identify' command.
When I run which identify, I get the expected path /usr/local/bin/identify. ImageMagick is indeed installed (via Homebrew), and appears to work with png images just fine from the command line.
I even rebuilt the app on another machine, thinking that my environment is borked, and I got the same error.
Is there a poltergeist in my terminal sessions?
Have you tried running a bundle exec before the rake. In the past this has often solved these sorts of problems for me. It will ensure your rails environment is loaded before running the rake task.
bundle exec rake db:seed
Hope that helps!
// Addition
Also are you using the Paperclip gem to do this import? I do remember that I needed to ensure the path to ImageMagick was set in my development.rb file to ensure this was picked up.
Eg.
Paperclip.options[:command_path] = "/usr/local/bin"