For example, if you wanted to export Photos records from Photogram.
In the photo.rb
model, define a class method called to_csv
.
class Photo < ApplicationRecord
For a reference, my script looks like:
FROM buildpack-deps:focal | |
### base ### | |
RUN yes | unminimize \ | |
&& apt-get install -yq \ | |
zip \ | |
unzip \ | |
bash-completion \ | |
build-essential \ | |
htop \ |
It is very helpful to take the time to pre-populate your database with some dummy data before you start working on any features. It's nice to have some data to look at to see whether you are going down the right path.
It's also very helpful to other developers on the project, so they can get started quickly right after they clone.
Here are two ways to create seed data:
class AddStatusToItem < ActiveRecord::Migration
def change
add_column :items, :scheduler_type, :string, default: "hotseat"
end
end
This gem is part of the standard ruby library, but we have to require it in our file so we can use the open method for our new_content variable.
I would still word it in more general terms. We need to require it in order to be able to open files from URLs not just files in our project.
wget -0 is a bash command
I would still say wget
is the bash command. The -O
is a flag that allows you to name the file that you download from the URL.
Very clear example of wget
here
This kind of script only really seems necessary if the person working in the project is not really aware of what all the files do— otherwise they could just copy/paste or use git
. Just want to mention that up front in case the audience for this post is any Ruby developer, some context on why we need this instead of some other solution, might be nice.
Specifically in our case, students are not aware that each test is in their workspace and that editing those files can affect their score.
This
wget -O bin/hello_world "url" && chmod 777 bin/hello_world && bin/hello_world