How to Build Task 'Gems:Install'

Can't install gem using Bundler's Rakefile install task when developing a custom gem

Yes, it has something to do with your PATH variables. Your installation seems to be good.

I advise you to first affirm your gems installation path with:

echo $GEM_HOME

The double check your PATH to ensure its present and also confirm that the GEM home is also where the gem got installed into from the rake install

echo $PATH

If not, put it in your path and you should be fine with something like this:

echo PATH=$PATH:$GEM_HOME >> ~/.bashrc
source ~/.bashrc

Rake task for installing gem migrations executing only once

The invoke method only runs "as needed", which basically means that once it's run once, it wont run again unless reenabled.

You can either call .reenable after each .invoke to reset it, or use the .execute command to run the task.

The caveat with .execute is that it won't run the dependencies for the task if you have them.

Why is Rake not able to invoke multiple tasks consecutively?

How to run Rake tasks from within Rake tasks?

rails aborted Don't know how to build task 'AdminUser.create!()

There are several ways to add that admin into the database:

  1. rails console - Just open the console and execute AdminUser.create!(...).
  2. seeds.rb - Open the db/seeds.rb file and paste AdminUser.create!(...). Then run rake db:seed. Note that running rake db:seed multiple times will create that admin multiple times - it's best you have some sort of validations or use AdminUser.find_or_create_by(...) instead.
  3. rake task - create a rake file in lib/tasks, name is not important but it should end in .rake (ex: update.rake)
task :add_admin do
AdminUser.find_or_create_by(email: "admin@gmail.com", password: "password", password_confirmation: "password")
end

Run it with rake add_admin.

If you want that admin only for yourself, your local machine, use the console approach, otherwise pick the other two but make sure the rake tasks are idempotent.

Installing gems tries to load the gems in my custom rake tasks before installing it

this might work? delay the requires on your rake task by moving them into the task itself

task :fixtures => [:environment] do
require 'rubygems'
require 'ya2yaml'
# ...

by default running rake tasks 'loads' all of the rake files

Local rake tasks require development gems to be in production group

Maybe not the most exciting answer but I just moved the require 'dev_gem' inside the rake task block for that task.

namespace :elasticbeanstalk do
desc 'Creates a new web & worker environment pair for testing'
task :create do
require 'aws-sdk-elasticbeanstalk'

# Do stuff with beanstalk that we wouldn't from a production env
end
end

This way the library only gets loaded when the rake task is invoked rather than when the rake task is defined.



Related Topics



Leave a reply



Submit