# rake

Published articles for rake.

This is one page of public article previews, not the complete archive. Follow Next page to continue. Summaries are not the original full articles.

## Declaring Ruby Bankruptcy, The Ruby Psych 3.1 Issue, RVM and RBEnv

DevFeed: [Declaring Ruby Bankruptcy, The Ruby Psych 3.1 Issue, RVM and RBEnv](<https://devfeed.tech/articles/declaring-ruby-bankruptcy-the-ruby-psych-3-1-issue-rvm-and-rbenv-28316.md>)

Original publisher: [Read original article](<http://fuzzyblog.io/blog/ruby/2022/06/15/declaring-ruby-bankruptcy-the-ruby-psych-3-1-issue-rvm-and-rbenv.html>)

Author: Fuzzygroup

Published: 2022-06-15T06:35:00Z

Content type: opinion

Language: en

Sources: [Scott Johnson](<https://devfeed.tech/sources/scott-johnson.md>)

Topics: [Ruby](<https://devfeed.tech/topics/ruby.md>), [Development](<https://devfeed.tech/topics/development.md>), [legacy](<https://devfeed.tech/topics/legacy.md>)

Tags: [errors](<https://devfeed.tech/tags/errors.md>), [installation](<https://devfeed.tech/tags/installation.md>), [legacy](<https://devfeed.tech/tags/legacy.md>), [rails](<https://devfeed.tech/tags/rails.md>), [rake](<https://devfeed.tech/tags/rake.md>), [rbenv](<https://devfeed.tech/tags/rbenv.md>), [ruby](<https://devfeed.tech/tags/ruby.md>), [rvm](<https://devfeed.tech/tags/rvm.md>), [zsh](<https://devfeed.tech/tags/zsh.md>)

### AI overview

A developer describes problems after installing Ruby 3.1 with RVM, including missing psych and failures in bundle install, irb, Rails console, rake, and switching Ruby versions. After removing RVM and rbenv, the author plans to use RVM for Ruby 3.1 and later and rbenv for older projects.

### Source excerpt

I had a bloody awful Sunday three days ago. I had started work on a new application that had Ruby 3.1 set in its Gemfile and I blithely installed Ruby 3.1 using RVM. And then my life began to suck slimy green toads with errors like this: /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/yaml.rb:3: warning: It seems your ruby installation is missing psych (for YAML output). To eliminate this warning, please install libyaml and reinstall your ruby. I'd like to say that I wasn't quite as diligent in fixing this because, well, it was sunday. However, given the readiness by which most of us generally install new versions of ruby, that wasn't it. We simply aren't used to breaking changes with Ruby. The ctrl blog does a great job of describing this. Thank you. The basic issue is that psych is a low level gem and once it changes, well, your world kind of just breaks. What I pretty much found out immediately is that every single thing I wanted to do with Ruby just failed: bundle install irb rails c rake And, "drum roll" - changing over to a different ruby The fact that I couldn't change over to a different ruby basically meant that I was screwed. I don't think that this was intended. And it is entirely possible that this was some kind of whacky interaction on a development system with, ahem, a lot of rubies and crazy legacy conflicts but that is what happened. Declaring Ruby Bankruptcy Since I couldn 't change rubies, everything just devolved into an amazing pool of suckitude. Not only couldn't I use Ruby, I couldn't blog, run any of my utility scripts, etc. My final answer was to declare ruby bankruptcy and: delete rvm delete rbenv delete all references to rvm and rbenv from zsh and other profile files reboot rm -rf ~/.rvm rm -rf ~/.rbenv reboot I've been a long time Ruby user so this process exposed some craziness like 2.3.1 log files owned by root which couldn't be deleted. Taking a Break This was the point where I threw my hands up, walked away an

## Rails 7 Madness: No such middleware to insert before: ActionDispatch::Static

DevFeed: [Rails 7 Madness: No such middleware to insert before: ActionDispatch::Static](<https://devfeed.tech/articles/rails-7-madness-no-such-middleware-to-insert-before-actiondispatch-static-28277.md>)

Original publisher: [Read original article](<http://fuzzyblog.io/blog/rails/2022/06/02/rails-7-madness-no-such-middleware-to-insert-before-actiondispatch-static.html>)

Author: Fuzzygroup

Published: 2022-06-02T04:22:00Z

Content type: tutorial

Language: en

Sources: [Scott Johnson](<https://devfeed.tech/sources/scott-johnson.md>)

Topics: [Rails](<https://devfeed.tech/topics/rails.md>), [Vite](<https://devfeed.tech/topics/vite.md>), [Ruby](<https://devfeed.tech/topics/ruby.md>), [npm packages](<https://devfeed.tech/topics/npm-packages.md>)

Tags: [deploy](<https://devfeed.tech/tags/deploy.md>), [errors](<https://devfeed.tech/tags/errors.md>), [hatchbox](<https://devfeed.tech/tags/hatchbox.md>), [logging](<https://devfeed.tech/tags/logging.md>), [npm-packages](<https://devfeed.tech/tags/npm-packages.md>), [rails](<https://devfeed.tech/tags/rails.md>), [rake](<https://devfeed.tech/tags/rake.md>), [troubleshooting](<https://devfeed.tech/tags/troubleshooting.md>), [vite](<https://devfeed.tech/tags/vite.md>)

### AI overview

A troubleshooting account of a Rails 7 deployment error reporting that no middleware could be inserted before ActionDispatch::Static. The author reproduced the issue with Rails commands, added the smart_assets gem, and then encountered a different deployment failure indicating that the Vite binary was unavailable.

### Source excerpt

In tonight's category of "Crazy Rails Errors that Even I haven't hit", I was deploying a new app via HatchBox and I hit this one: No such middleware to insert before: ActionDispatch::Static /home/deploy/Cartazzi/shared/bundle/ruby/3.1.0/gems/actionpack-7.0.2.2/lib/action_dispatch/middleware/stack.rb:174:in `assert_index' When I dug into the underlying failure there was this bit of code: def assert_index(index, where) i = index.is_a?(Integer) ? index : index_of(index) raise "No such middleware to insert #{where}: #{index.inspect}" unless i i end I did the obligatory googling only to find nothing in the past year and absolutely nothing related to Rails 7. I was able to replicate this by logging in with either: bundle exec rake middleware or RAILS_ENV=production bundle exec rake assets:precompile After stumbling around a bit - this was post midnight late night code fu - I thoguht to myself: What if the issue is that it is looking for middleware and it can't find any? One of the previous googles from 2015 or so said that if you have this issue then remove the font_assets gem (I didn't have it but omitted that part of the research above). What I did was look for asset pipeline middleware and I found the smart_assets gem which I dropped into Gemfile: gem 'smart_assets' A quick bundle install and I ended up with a failing deploy ... but a different failure: Building with Vite rake aborted! ViteRuby::MissingExecutableError: The vite binary is not available. Have you installed the npm packages? Visit the Troubleshooting guide for more information: https://vite-ruby.netlify.app/guide/troubleshooting.html#troubleshooting And that, in modern computing, alas, is progress.

## Rails 6 - Can't Find Application.js

DevFeed: [Rails 6 - Can't Find Application.js](<https://devfeed.tech/articles/rails-6-can-t-find-application-js-28273.md>)

Original publisher: [Read original article](<http://fuzzyblog.io/blog/rails/2021/12/18/rails-6-can-t-find-application-js.html>)

Author: Fuzzygroup

Published: 2021-12-18T14:51:00Z

Content type: tutorial

Language: en

Sources: [Scott Johnson](<https://devfeed.tech/sources/scott-johnson.md>)

Topics: [Rails](<https://devfeed.tech/topics/rails.md>), [Yarn](<https://devfeed.tech/topics/yarn.md>), [Development](<https://devfeed.tech/topics/development.md>)

Tags: [asset-pipeline](<https://devfeed.tech/tags/asset-pipeline.md>), [bash](<https://devfeed.tech/tags/bash.md>), [command](<https://devfeed.tech/tags/command.md>), [compilation](<https://devfeed.tech/tags/compilation.md>), [foreman](<https://devfeed.tech/tags/foreman.md>), [git](<https://devfeed.tech/tags/git.md>), [js](<https://devfeed.tech/tags/js.md>), [rails](<https://devfeed.tech/tags/rails.md>), [rake](<https://devfeed.tech/tags/rake.md>)

### AI overview

A troubleshooting note about a Rails 6 project where Webpacker cannot find application.js. It explains installing Webpacker and using bin/dev with Foreman so the JavaScript and CSS asset processes run.

### Source excerpt

So I started fiddling about with a new Rails project and after finding a likely starting point, I immediately ended up with this: Webpacker can't find application.js in I'm old school Rails and I find the whole asset compilation situation, honestly, perplexing. The solution turned out to be: bundle exec rails webpacker:install after the normal: git clone foo bundle install bundle exec rake db:migrate I have no idea why the bundler install doesn't handle executing webpacker:install but cie la vie. The more things change, the more they stay the same ... Update: I kept at this and kept finding that I didn't have webpacker or some other portion of the rails stack running. I finally traced this down to things having changed. Traditionally I've always run rails as: bundle exec rails s -pXYZ And the new approach is to run: bin/dev which in turn contains: #!/usr/bin/env bash if ! command -v foreman &> /dev/null then echo "Installing foreman..." gem install foreman fi foreman start -f Procfile.dev "$@" and the Procfile.dev file contains: web: bin/rails server -p 3000 js: yarn build --watch css: yarn build:css --watch I was literally missing the yarn command so part of the overall asset pipeline just wasn't running. Old habits die hard.

## Loading Zip Codes with SmarterCSV Gem

DevFeed: [Loading Zip Codes with SmarterCSV Gem](<https://devfeed.tech/articles/loading-zip-codes-with-smartercsv-gem-28266.md>)

Original publisher: [Read original article](<http://fuzzyblog.io/blog/rails/2020/03/18/loading-zip-codes-with-smartercsv-gem.html>)

Author: Fuzzygroup

Published: 2020-03-18T00:00:00Z

Content type: tutorial

Language: en

Sources: [Scott Johnson](<https://devfeed.tech/sources/scott-johnson.md>)

Topics: [Rails](<https://devfeed.tech/topics/rails.md>), [CSV](<https://devfeed.tech/topics/csv.md>), [Code](<https://devfeed.tech/topics/code.md>), [import](<https://devfeed.tech/topics/import.md>), [data](<https://devfeed.tech/topics/data.md>)

Tags: [code](<https://devfeed.tech/tags/code.md>), [covidnearme-org](<https://devfeed.tech/tags/covidnearme-org.md>), [csv](<https://devfeed.tech/tags/csv.md>), [data](<https://devfeed.tech/tags/data.md>), [import](<https://devfeed.tech/tags/import.md>), [rails](<https://devfeed.tech/tags/rails.md>), [rake](<https://devfeed.tech/tags/rake.md>), [trace](<https://devfeed.tech/tags/trace.md>), [transformation](<https://devfeed.tech/tags/transformation.md>), [zip](<https://devfeed.tech/tags/zip.md>)

### AI overview

A Rails example shows how to load U.S. ZIP code data with the SmarterCSV gem while preserving leading zeros. It uses a rake task and excludes the ZIP field from numeric conversion because the documented transformation did not work as expected.

### Source excerpt

Zip code data is always problematic due to the leading zeros. The smarter_csv gem in Rails defaults to automatically handling numbers as numerics, not strings, which means that you lose 00408 to just 408. Here's an example of a work around using a rake task to load data: # bundle exec rake data:import_geography --trace task :import_geography => :environment do path = File.join(Rails.root, 'lib/tasks/data/', 'Geocodes_USA_with_Counties.csv') geographies = SmarterCSV.process(path, { hash_transformations: [ :convert_values_to_numeric_unless_leading_zeros], convert_values_to_numeric: { except: [:zip] }} ) geographies.each do |g| g_obj = Geography.find_or_create(g) end end Note: This wasn't the accepted work around but a hack; sigh. The :convert_values_to_numeric_unless_leading_zeros transformation doesn't seem work. Issue filed; I hope to fix this myself down the road.

## When to Use a Helper Method in Rails

DevFeed: [When to Use a Helper Method in Rails](<https://devfeed.tech/articles/when-to-use-a-helper-method-in-rails-28265.md>)

Original publisher: [Read original article](<http://fuzzyblog.io/blog/rails/2020/03/04/when-to-use-a-helper-method-in-rails.html>)

Author: Fuzzygroup

Published: 2020-03-04T00:00:00Z

Content type: tutorial

Language: en

Sources: [Scott Johnson](<https://devfeed.tech/sources/scott-johnson.md>)

Topics: [Rails](<https://devfeed.tech/topics/rails.md>), [Ruby](<https://devfeed.tech/topics/ruby.md>), [Code](<https://devfeed.tech/topics/code.md>), [HTML](<https://devfeed.tech/topics/html.md>)

Tags: [code](<https://devfeed.tech/tags/code.md>), [data-structure](<https://devfeed.tech/tags/data-structure.md>), [function](<https://devfeed.tech/tags/function.md>), [html](<https://devfeed.tech/tags/html.md>), [netlabeler](<https://devfeed.tech/tags/netlabeler.md>), [rails](<https://devfeed.tech/tags/rails.md>), [rake](<https://devfeed.tech/tags/rake.md>), [ruby](<https://devfeed.tech/tags/ruby.md>), [view](<https://devfeed.tech/tags/view.md>)

### AI overview

This Rails tutorial explains when to use a helper method to transform stored hash data into HTML for display. It presents a testable display_labeled_data helper that builds paragraph output, converts newlines to HTML breaks, joins the result, and marks it html_safe. It also notes that Rails helpers share a global namespace.

### Source excerpt

One of the more interesting facilities in Rails helpers which reside in app/helpers/*.rb and are used, well, as helpers. Helpers are basically display level execution of Ruby code. I recently wrote what I thought was a great example of a helper so I thought I'd document it. What I had was a object, stored in the database which had a bunch of data that I needed to display: the object, called a label A serialized hash called labeled_data label0 label1 label2 label3 label4 label5 label6 label7 label8 label9 What I wanted to do was transform this, at display time, to an HTML structure like this: <p>label0: <b>The Data for Label 0</b> <p>label1: <b>The Data for Label 0</b> and, correctly, not show label2, etc if they were blank. And, naturally, do the right thing when there was no data in the labeled_data hash, etc. And while I could have done this with a view and code wrapped in evaluation / output tags: <% and %> or <%= or %> it is dramatically cleaner to write this type of thing as a helper and then call it as a function like display_labeled_data(label). Not only does this make the code much cleaner than evaluation / output tags, it also has the advantage of being testable. Now all that said, here is the code: def display_labeled_data(label) return if label.labeled_data.nil? return if label.labeled_data.keys.nil? output = [] label.labeled_data.keys.each do |key| output << "<p>" output << key output << ":" tmp = label.extracted_data[key] if tmp tmp = tmp.gsub(/\n/,'
') end output << tmp output << "</p>" end output.join("\n").html_safe end The key idea here is: create an output object, in this case an array or [] loop a data structure - label.labeled_data.keys as you loop the data structure, put things into the output object like a paragraph tag, the name of the key i.e. "label0", a ':' clean up the data by converting new lines to html line breaks add the data into the output element add a closing p tag add a line break onto every element of the output object (using

## Getting Past the unpack1 error on Heroku

DevFeed: [Getting Past the unpack1 error on Heroku](<https://devfeed.tech/articles/getting-past-the-unpack1-error-on-heroku-28111.md>)

Original publisher: [Read original article](<http://fuzzyblog.io/blog/2019/12/29/getting-past-the-unpack1-error-on-heroku.html>)

Author: Fuzzygroup

Published: 2019-12-29T00:00:00Z

Content type: tutorial

Language: en

Sources: [Scott Johnson](<https://devfeed.tech/sources/scott-johnson.md>)

Topics: [Heroku](<https://devfeed.tech/topics/heroku.md>), [Rails](<https://devfeed.tech/topics/rails.md>), [Ruby](<https://devfeed.tech/topics/ruby.md>), [hosting](<https://devfeed.tech/topics/hosting.md>)

Tags: [config](<https://devfeed.tech/tags/config.md>), [credentials](<https://devfeed.tech/tags/credentials.md>), [git](<https://devfeed.tech/tags/git.md>), [heroku](<https://devfeed.tech/tags/heroku.md>), [hosting](<https://devfeed.tech/tags/hosting.md>), [logs](<https://devfeed.tech/tags/logs.md>), [rails](<https://devfeed.tech/tags/rails.md>), [rake](<https://devfeed.tech/tags/rake.md>)

### AI overview

A troubleshooting article documenting Heroku deployment commands and logs for an encrypted Rails credentials failure. The supplied error reports that the encryption key must be 16 bytes.

### Source excerpt

11373* heroku domains:add okrsnow.com 11374* heroku domains:add www.okrsnow.com 11376* mate _posts/2019-12-29-heroku-and-route-53-using-amazon-for-domain-registration-with-heroku-for-hosting.md 11377* heroku logs 11378* heroku logs -tail 11379* heroku config:set RAILS_MASTER_KEY=123456789abcefg 11380* git push heroku master 11384* git push heroku master 11385* heroku logs -tail 11390* git push heroku master 11391* heroku config:set RAILS_MASTER_KEY=config/credentials/production.yml.enc 11395* git push heroku master 11396* heroku config:set RAILS_MASTER_KEY=f9d510292a72197cb71c44617a6f71690ebe5fde9aaf7c0b19dc0427aeef62e2143e271260e169fd04ab3681f1df173d6079c740f8aeafff491787974809b9aa 11397* git push heroku master 11399* heroku config:set RAILS_MASTER_KEY=65371bc52c911ea14494c5905c07c1cf 11400* git push heroku master 11402 heroku logs tail -f 11404 heroku logs -tail 11409 heroku logs -tail 11411 history | grep heroku 11412 heroku config 11413 bundle exec heroku rake db:migrate 11414 bundle exec heroku rake seed:init https://jumpstartrails.com/discussions/88 remote: /tmp/build_b70efc9d2ecef8d7607b7096a75f9e13/vendor/bundle/ruby/2.6.0/gems/rake-13.0.1/exe/rake:27:in <top (required)>' remote: remote: Caused by: remote: ArgumentError: key must be 16 bytes remote: /tmp/build_b70efc9d2ecef8d7607b7096a75f9e13/vendor/bundle/ruby/2.6.0/gems/activesupport-6.0.2.1/lib/active_support/message_encryptor.rb:193:in key=' remote: /tmp/build_b70efc9d2ecef8d7607b7096a75f9e13/vendor/bundle/ruby/2.6.0/gems/activesupport-6.0.2.1/lib/active_support/message_encryptor.rb:193:in _decrypt' remote: /tmp/build_b70efc9d2ecef8d7607b7096a75f9e13/vendor/bundle/ruby/2.6.0/gems/activesupport-6.0.2.1/lib/active_support/message_encryptor.rb:157:in decrypt_and_verify' remote: /tmp/build_b70efc9d2ecef8d7607b7096a75f9e13/vendor/bundle/ruby/2.6.0/gems/activesupport-6.0.2.1/lib/active_support/messages/rotator.rb:21:in `decrypt_and_verify' remote

## Using a Cron Job to Run Rake Tasks Inside Your Docker Container

DevFeed: [Using a Cron Job to Run Rake Tasks Inside Your Docker Container](<https://devfeed.tech/articles/using-a-cron-job-to-run-rake-tasks-inside-your-docker-container-28157.md>)

Original publisher: [Read original article](<http://fuzzyblog.io/blog/docker/2019/11/29/using-a-cron-job-to-run-rake-tasks-inside-your-docker-container.html>)

Author: Fuzzygroup

Published: 2019-11-29T00:00:00Z

Content type: tutorial

Language: en

Sources: [Scott Johnson](<https://devfeed.tech/sources/scott-johnson.md>)

Topics: [Docker](<https://devfeed.tech/topics/docker.md>), [container](<https://devfeed.tech/topics/container.md>), [Bash](<https://devfeed.tech/topics/bash.md>), [Job](<https://devfeed.tech/topics/job.md>)

Tags: [bash](<https://devfeed.tech/tags/bash.md>), [container](<https://devfeed.tech/tags/container.md>), [docker](<https://devfeed.tech/tags/docker.md>), [job](<https://devfeed.tech/tags/job.md>), [rails](<https://devfeed.tech/tags/rails.md>), [rake](<https://devfeed.tech/tags/rake.md>), [run](<https://devfeed.tech/tags/run.md>), [scheduling](<https://devfeed.tech/tags/scheduling.md>), [shell](<https://devfeed.tech/tags/shell.md>), [shell-script](<https://devfeed.tech/tags/shell-script.md>)

### AI overview

This tutorial explains how to use an OS-level cron job to run a Rake task inside a Docker container. It shows how to execute a shell in the container, run the task with Docker, and use a shell script to obtain the container hash dynamically because the hash changes when the container restarts.

### Source excerpt

Despite cron being an age old *nix technology, it alway seems like scheduling tasks is an annoying thing. Note: Cron is the standard *nix technology for running tasks on a recurring basis like "every monday at 5 am execute this program". We are now doing things like running tasks within containers and that raises the question of where does cron exist: within the container? at the OS level? what about multiple instances of the container across different machines? I'm not going to try and address the bigger picture questions here like multiple instances but I can show you how to use cron at the OS level to drive a rake task within a container. How Do You Run Something Within in a Container The first thing to understand is that you can easily execute a shell with in a container, from the outside, with this syntax: docker exec -it CONTAINER_HASH /bin/bash The CONTAINER_HASH is the docker equivalent of a *nix pid (process identifier). How to Run a Rake Task And if you can run a shell like /bin/bash within a container from the outside then, drum roll please, you can easily run anything from outside including a Rake task. And if you have that then you can easily schedule it. Here's an example: docker exec -it 8d76da4ab481 bundle exec rake data_source:update_or_initial_load --trace The 8d76da4ab481, shown above, is an example of the CONTAINER_HASH. But Docker Container Hashes Change... If you think about this a bit there is one real problem - that damn CONTAINER_HASH isn't consistent. It changes every time the container is restarted. The trick to making a cron job that runs your rake task is to use a shell script which pulls the container hash dynamically. And to figure that you we are going to start with my dockerbash blog post. Here's the shell script from the dockerbash post: #!/bin/bash if [ -z $1 ]; then echo "You need to specify the name of the container you want to get into like:" echo "dockerbash police" else pid=`docker ps | grep $1 | awk '{print $1}'` docker exec -i

## Getting Local Development Data for Rails from Your Production Site using Heroku

DevFeed: [Getting Local Development Data for Rails from Your Production Site using Heroku](<https://devfeed.tech/articles/getting-local-development-data-for-rails-from-your-production-site-using-heroku-28244.md>)

Original publisher: [Read original article](<http://fuzzyblog.io/blog/rails/2019/11/16/getting-local-development-data-for-rails-from-your-production-site-using-heroku.html>)

Author: Fuzzygroup

Published: 2019-11-16T00:00:00Z

Content type: tutorial

Language: en

Sources: [Scott Johnson](<https://devfeed.tech/sources/scott-johnson.md>)

Topics: [Rails](<https://devfeed.tech/topics/rails.md>), [Heroku](<https://devfeed.tech/topics/heroku.md>), [MySQL](<https://devfeed.tech/topics/mysql.md>), [Databases](<https://devfeed.tech/topics/databases.md>), [Development](<https://devfeed.tech/topics/development.md>)

Tags: [backup](<https://devfeed.tech/tags/backup.md>), [database](<https://devfeed.tech/tags/database.md>), [heroku](<https://devfeed.tech/tags/heroku.md>), [mysql](<https://devfeed.tech/tags/mysql.md>), [rails](<https://devfeed.tech/tags/rails.md>), [rake](<https://devfeed.tech/tags/rake.md>), [test-coverage](<https://devfeed.tech/tags/test-coverage.md>)

### AI overview

A tutorial explaining how to copy production data from a Heroku-hosted Rails application into a local development environment. It uses MySQL export and import commands, recommends backing up local data first, and provides a Rake task to simplify the workflow.

### Source excerpt

One of the worst aspects of doing Rails development, although this is not limited to Rails in any way, is getting data to use for development work once your site starts getting users. Yes I know that you should always have full test coverage and that local data shouldn't be necessary - but it absolutely is. There is always a class of errors that you simply can't diagnose with a set of data with which to work. The happy truth though is that you actually can pretty easily move data from production to development at will (at least as long as the database isn't too massive; when your site gets large it is a different matter). The Approach The approach here is actually pretty simple. My examples all center around using MySQL as a data store but any database that has solid import / export will work. To start you should backup your local data just in case you need it back afterwards. You then connect to your remote datastore and use mysqldump to export your data to a local data dump. You then import this local data dump. You debug your site using a much richer set of data. Making this Easy with a Rake Task Here's a rake task that I wrote that gives you a lot of tasks for dealing with your local / remote databases. Drop this into lib/tasks and you can see the tasks it offers with: bundle exec rake -T | grep database namespace :database do namespace :development do # Generates a mysql load command # bundle exec rake database:development:mysql_load_data_command --trace task :mysql_load_data_command => :environment do #username, password, database db_params = get_local_database_params command = make_mysql_command('mysql', db_params, ' < lib/tasks/data/db_dumps/') puts "Add the load file into the below command " puts " once you copy and paste it back into the terminal" puts command end # generates a mysql command to get into the database # bundle exec rake database:development_mysql_command --trace task :mysql_command => :environment do db_params = get_local_database_params com

## Writing a one-time script in Rails

DevFeed: [Writing a one-time script in Rails](<https://devfeed.tech/articles/writing-a-one-time-script-in-rails-26280.md>)

Original publisher: [Read original article](<https://www.justinweiss.com/articles/writing-a-one-time-script-in-rails/>)

Author: Justin Weiss

Published: 2017-02-14T06:08:51Z

Content type: tutorial

Language: en

Sources: [Justin Weiss](<https://devfeed.tech/sources/justin-weiss.md>)

Topics: [Rails](<https://devfeed.tech/topics/rails.md>), [Script](<https://devfeed.tech/topics/script.md>), [data](<https://devfeed.tech/topics/data.md>), [migration](<https://devfeed.tech/topics/migration.md>), [import](<https://devfeed.tech/topics/import.md>), [CSV](<https://devfeed.tech/topics/csv.md>), [Database](<https://devfeed.tech/topics/database.md>)

Tags: [capistrano](<https://devfeed.tech/tags/capistrano.md>), [csv](<https://devfeed.tech/tags/csv.md>), [data](<https://devfeed.tech/tags/data.md>), [database](<https://devfeed.tech/tags/database.md>), [heroku](<https://devfeed.tech/tags/heroku.md>), [import](<https://devfeed.tech/tags/import.md>), [job](<https://devfeed.tech/tags/job.md>), [migration](<https://devfeed.tech/tags/migration.md>), [other](<https://devfeed.tech/tags/other.md>), [rails](<https://devfeed.tech/tags/rails.md>), [rake](<https://devfeed.tech/tags/rake.md>), [scheduler](<https://devfeed.tech/tags/scheduler.md>), [script](<https://devfeed.tech/tags/script.md>), [sidekiq](<https://devfeed.tech/tags/sidekiq.md>), [structure](<https://devfeed.tech/tags/structure.md>)

### AI overview

This Rails tutorial explains how to handle one-time data tasks, comparing database migrations with rake tasks and scheduled background jobs. It recommends rake tasks for code that must be tested locally and run in production, while noting when migrations are appropriate and what risks model changes can create.

### Source excerpt

Have you ever wanted to import a bunch of data into your app from a CSV file? Or maybe you need to fix badly encoded characters in some of your customer reviews. Or you changed your mind about how you wanted to store data in Redis, and had to move everything from the old format to the new one. At Avvo, we called these "ad-hoc tasks." As in, you probably only need to run them once. So what's the best way to handle an ad-hoc task in Rails? Write a database migration A migration works well if you need to change the structure of the data in your database. It tracks whether the task was run, it carries over changes to other environments - it's what migrations were built for. It's also what you're probably already using them for. If you're changing data at the same time, a migration might work well. But there are some things to watch out for. Calling something like Permissions.create(...) in your migration can cause you trouble. If the model has changed, your migration might break, because your model might not be available when the migration runs. Or your model might have changed between the time you wrote the migration and when it ran. There are ways to get around this, but they're error-prone and can fail in weird ways. Migrations are also less useful if your task doesn't involve ActiveRecord. These aren't deal-breakers. But I tend not to import or change much data in migrations. There are better options. Write a rake task You have a task. You probably only want to run it once. And you want to be able to test it on your machine and run it in production. Rake tasks work really well for this. Rails can even generate rake tasks for you: $ be rails g task locations import create lib/tasks/locations.rake This creates a file for you to stash your code into: lib/tasks/locations.rakenamespace :locations do desc "TODO" task import: :environment do end end Inside that task block, you can use all your models and the rest of the code in your Rails app. It's easy to import and chang

## Scripting with rake

DevFeed: [Scripting with rake](<https://devfeed.tech/articles/scripting-with-rake-33367.md>)

Original publisher: [Read original article](<https://timkellogg.me/blog/2011/04/20/scripting-with-rake>)

Published: 2011-04-20T00:00:00Z

Content type: tutorial

Language: en

Sources: [Tim Kellogg](<https://devfeed.tech/sources/tim-kellogg.md>)

Topics: [Ruby](<https://devfeed.tech/topics/ruby.md>), [make](<https://devfeed.tech/topics/make.md>), [Command-line interface](<https://devfeed.tech/topics/cli.md>), [ASP.NET](<https://devfeed.tech/topics/aspnet.md>), [NUnit](<https://devfeed.tech/topics/nunit.md>), [Visual Studio](<https://devfeed.tech/topics/visual-studio.md>)

Tags: [asp-net](<https://devfeed.tech/tags/asp-net.md>), [cli](<https://devfeed.tech/tags/cli.md>), [dependencies](<https://devfeed.tech/tags/dependencies.md>), [make](<https://devfeed.tech/tags/make.md>), [net](<https://devfeed.tech/tags/net.md>), [nunit](<https://devfeed.tech/tags/nunit.md>), [rake](<https://devfeed.tech/tags/rake.md>), [ruby](<https://devfeed.tech/tags/ruby.md>), [visual-studio](<https://devfeed.tech/tags/visual-studio.md>)

### AI overview

This article explains how to use Rake as a Ruby-based build and scripting tool. It compares Rake with make, Ant, and NAnt, discusses dependency and file tasks, and describes using Albacore for .NET builds and related development automation.

### Source excerpt

Rake is a great twist on traditional make (honestly, I never really liked Ant or NAnt). On the surface it looks more like make than Ant or Nant, but you can leverage the full syntax and standard library of Ruby (and there's no weird rules about tabs). As a .NET developer, albacore augments rake nicely with tasks for MSBuild (building Visual Studio projects and solutions), NUnit, ASP.NET precompiler, modifying your AssemblyInfo.cs (like for bumping the version number), and many more.Since rake is just ruby code, you can do just about anything, but most file manipulation routines are even easier to write in rake, because most everything is already imported and ready to use. Unlike make, Ant, and Nant, you don't have to start a separate project just to develop tools to use in a rakefile, just write a ruby function!Building dependencies firstA lot of people who aren't already familiar with build languages make some common mistakes. Among them, not using dependencies correctly. For instance, given a website solution that references frameworkmsbuild :framework do |msb| msb.solution = 'framework/src/framework.sln'endmsbuild :website do |msb| msb.solution = 'src/website.sln'endtask :default => [:framework, :website]The default task is the task that's executed when you just type rake at the CLI. The reason this is terrible is that it's procedural and inflexible. Now, if I do rake website the build fails because framework hasn't been built yet. Instead, each task should specify what other tasks it directly relies on. This script should change to:msbuild :framework do |msb| msb.solution = 'framework/src/framework.sln'endmsbuild :website => :framework do |msb| msb.solution = 'src/website.sln'endtask :default => :websiteThis way both rake and rake website work the same. This leverages rakes dependency framework that is at the core of all build languages.Using file tasksThe other point that people often forget is that build languages are oriented around files. Make tasks were ori