### Final Application Setup Source: https://developers.forem.com/getting-started/installation/linux Performs the final setup for the Forem application, including installing required Ruby gems and NodeJS modules. ```bash ./bin/setup ``` -------------------------------- ### Start Database (PostgreSQL) Source: https://developers.forem.com/getting-started/installation/linux Starts the PostgreSQL database server. This command should be run every time you work on Forem. ```bash pg_ctl start ``` -------------------------------- ### Start Forem Application Source: https://developers.forem.com/getting-started/installation/linux Starts the Forem development server. After successful startup, the Forem application should be accessible at http://localhost:3000. ```bash ./bin/startup ``` -------------------------------- ### Troubleshoot bin/setup Issues Source: https://developers.forem.com/getting-started/start-app If 'bin/setup' fails, try running the Rails server directly with 'bin/rails s -p 3000'. You might need to run 'yarn install' first. This helps resolve environment or dependency issues. ```bash bin/rails s -p 3000 ``` -------------------------------- ### Start Forem Application with bin/startup Source: https://developers.forem.com/getting-started/start-app This command starts the Forem application, including Webpack and Sidekiq. It's a shortcut for 'foreman start -f Procfile.dev'. Ensure you have Foreman installed. After running, access the site at http://localhost:3000. ```bash bin/startup ``` -------------------------------- ### Create Alias for Starting Application Source: https://developers.forem.com/getting-started/start-app To simplify starting the application, create a shell alias. This command sets up an alias named 'start' that executes 'bin/startup', allowing you to start the app with a single word command. ```bash alias start="bin/startup" ``` -------------------------------- ### Create PostgreSQL User Source: https://developers.forem.com/getting-started/installation/linux Creates a PostgreSQL user with the same username as the current system user. This is a one-time setup step. ```bash createuser -U postgres -s $(whoami) ``` -------------------------------- ### Start Caching Server (Redis) Source: https://developers.forem.com/getting-started/installation/linux Starts the Redis caching server in daemonized mode. This command should be run every time you work on Forem. ```bash redis-server --daemonize yes ``` -------------------------------- ### Example Initializer Calls Source: https://developers.forem.com/frontend/javascript-approaches/packs This snippet shows examples of initializer functions that are executed upon page load. These functions are part of the Webpacker setup and are responsible for initializing specific functionalities or behaviors on the page, similar to how `initializePage.js` worked in the asset pipeline. ```javascript initializeCommentDate(); initializeCommentPreview(); initializeNotifications(); initializeTimeFixer(); initializeDateHelpers(); ``` -------------------------------- ### Run RSpec Tests Source: https://developers.forem.com/getting-started/installation/linux Executes RSpec tests, with an example targeting tests for the 'acts_as_taggable_on' library. ```bash ./bin/rspec spec/lib/acts_as_taggable_on ``` -------------------------------- ### Install PostgreSQL via Homebrew Source: https://developers.forem.com/getting-started/installation/postgresql Command to install the PostgreSQL database server on macOS using the Homebrew package manager. ```bash brew install postgresql ``` -------------------------------- ### Install and Verify Vault Source: https://developers.forem.com/getting-started/installation/vault Commands to install Vault using Homebrew on macOS and verify the installation by checking the help output. This is the first step before starting a Vault server. ```bash vault -h ``` -------------------------------- ### Set Environment Variables Source: https://developers.forem.com/getting-started/installation/windows Example commands to export environment variables for the Forem application, such as GitHub API keys. ```bash export GITHUB_KEY="SOME_REAL_SECURE_KEY_HERE" export GITHUB_SECRET="ANOTHER_REAL_SECURE_KEY_HERE" ``` -------------------------------- ### Start Forem Application with Overmind Source: https://developers.forem.com/getting-started/start-app This command starts the Forem application using Overmind, a process manager that utilizes tmux. It allows for better control over application processes, log navigation, and service restarts. Requires Overmind to be installed. ```bash overmind s -f Procfile.dev ``` -------------------------------- ### Troubleshoot Installation Errors Source: https://developers.forem.com/getting-started/installation/windows Commands to resolve common installation failures, including missing system libraries or build tools like automake. ```bash sudo apt-get install libpq-dev ``` ```bash cd sudo apt-get update sudo apt-get install autoconf wget https://ftp.gnu.org/gnu/automake/automake-1.10.tar.gz tar xf automake-1.10.tar.gz cd automake-1.10/ ./configure --prefix=/usr/local make ``` -------------------------------- ### Prepare Test Database Source: https://developers.forem.com/getting-started/installation/linux Prepares the database specifically for running unit tests. ```bash ./bin/rails db:test:prepare RAILS_ENV=test ``` -------------------------------- ### Install Git Version Control System Source: https://developers.forem.com/getting-started/installation/linux Installs the Git version control system using the apt package manager. Git is essential for cloning the Forem repository from GitHub. This command updates the package list and then installs Git. ```bash sudo apt update && sudo apt install -y git ``` -------------------------------- ### Initialize Sidekiq Manually Source: https://developers.forem.com/getting-started/start-app If Sidekiq encounters 'No such file or directory' errors, it may need manual initialization. Run 'bundle exec sidekiq' in a separate terminal to start Sidekiq independently and allow it to set up properly. ```bash bundle exec sidekiq ``` -------------------------------- ### Install Ruby and Node.js Dependencies Source: https://developers.forem.com/getting-started/installation/windows Commands to install specific versions of Ruby and Node.js defined in the repository's version files using rbenv and nvm. ```bash rbenv install $(cat .ruby-version) rbenv global $(cat .ruby-version) ruby -v ``` ```bash nvm install $(cat .nvmrc) nvm use $(cat .nvmrc) node -v yarn -v ``` -------------------------------- ### Install Git and Clone Forem Repository Source: https://developers.forem.com/getting-started/installation/mac Commands to install the Git version control system using Homebrew and clone the Forem repository from GitHub. Users can choose between HTTPS or SSH protocols for the cloning process. ```shell brew install git git clone https://github.com//forem.git # OR git clone git@github.com:/forem.git cd forem ``` -------------------------------- ### Start Vault Development Server Source: https://developers.forem.com/getting-started/installation/vault Command to start a Vault server in development mode. This mode runs Vault in-memory and is suitable for testing and development, providing an unsealed server with a root token. ```bash vault server -dev ``` -------------------------------- ### Install rbenv and ruby-build on Ubuntu Source: https://developers.forem.com/getting-started/installation/windows Installs rbenv, a Ruby version manager, and its plugin ruby-build. It clones the repositories into the user's home directory and configures the shell environment to use them. ```bash cd git clone https://github.com/rbenv/rbenv.git ~/.rbenv echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc echo 'eval "$(rbenv init -)"' >> ~/.bashrc exec $SHELL git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc exec $SHELL ``` -------------------------------- ### Install System-Level Dependencies Source: https://developers.forem.com/getting-started/installation/mac Command to install all required system dependencies for Forem using a Homebrew bundle. This assumes a Brewfile is present in the current directory. ```shell brew bundle ``` -------------------------------- ### Configure Dockerized Selenium for WSL2 System Tests Source: https://developers.forem.com/getting-started/installation/windows Sets up a Selenium hub and Chrome node container to bypass WSL2 networking limitations. Requires Docker to be installed and running on the host machine. ```bash docker run -d --name selenium-hub -p 4444:4444 selenium/hub:3.141.59-20200409 CH=$(docker run --rm --name=ch --link selenium-hub:hub -v /dev/shm:/dev/shm selenium/node-chrome:3.141.59-20200409) export SELENIUM_URL="http://localhost:4444/wd/hub" ``` -------------------------------- ### Verify nvm Installation on Ubuntu Source: https://developers.forem.com/getting-started/installation/windows Checks if the Node Version Manager (nvm) is installed and accessible in the current shell environment. ```bash command -v nvm ``` -------------------------------- ### Debugging Breakpoint Example Source: https://developers.forem.com/getting-started/start-app This Ruby code snippet demonstrates how to use the 'pry' gem to set a breakpoint in a Rails controller. When the application execution reaches 'binding.pry', it will halt, allowing for interactive debugging. ```ruby def index a = "Hello debugger" binding.pry end ``` -------------------------------- ### Verify rbenv Installation on Ubuntu Source: https://developers.forem.com/getting-started/installation/windows Downloads and runs the rbenv-doctor script to verify that rbenv has been installed correctly and is configured properly. ```bash curl -fsSL https://raw.githubusercontent.com/rbenv/rbenv-installer/main/bin/rbenv-doctor | bash ``` -------------------------------- ### Install Version-Locked Tool Dependencies with Mise Source: https://developers.forem.com/getting-started/installation/linux Installs the exact versions of tools recommended for Forem development using the 'mise' tool. This helps prevent version conflicts. It may prompt to install plugins for Yarn, PostgreSQL, and Redis. This process can take several minutes as dependencies are built from source. ```bash mise install ``` -------------------------------- ### Install System-Level Dependencies for Forem Source: https://developers.forem.com/getting-started/installation/linux Installs essential system-level dependencies required for Forem development on Debian-based Linux distributions using apt. This includes ImageMagick, build tools, pkg-config, SSL/Zlib development headers, curl, and PostgreSQL/Redis related libraries. ```bash sudo apt update sudo apt install -y imagemagick curl build-essential pkg-config libssl-dev libz-dev libreadline-dev libcurl4-openssl-dev uuid-dev icu-devtools ``` -------------------------------- ### Install ImageMagick on WSL Source: https://developers.forem.com/getting-started/installation/windows Commands to update package repositories and install the ImageMagick suite, which is required by Forem for image processing. ```bash sudo apt update && sudo apt install imagemagick ``` -------------------------------- ### Liquid Tag Initialization and Rendering Example (Ruby) Source: https://developers.forem.com/frontend/liquid-tags An example of the `initialize` and `render` methods within a Liquid Tag. The `initialize` method processes input arguments, and `render` uses a partial view to generate the final HTML output. ```ruby def initialize(_tag_name, link, _parse_context) super stripped_link = ActionController::Base.helpers.strip_tags(link) the_link = stripped_link.split.first @embedded_url = KotlinTag.embedded_url(the_link) end def render(_context) ApplicationController.render( partial: PARTIAL, locals: { url: @embedded_url } ) end ``` -------------------------------- ### Install Foreman globally Source: https://developers.forem.com/getting-started/installation/others Installs the Foreman gem globally on the system. This is the recommended approach for Ruby projects to avoid conflicts with local application dependencies. ```bash gem install foreman ``` -------------------------------- ### Stop Database (PostgreSQL) Source: https://developers.forem.com/getting-started/installation/linux Shuts down the PostgreSQL database server. ```bash pg_ctl stop ``` -------------------------------- ### Stop Caching Server (Redis) Source: https://developers.forem.com/getting-started/installation/linux Shuts down the Redis caching server. ```bash redis-cli SHUTDOWN ``` -------------------------------- ### Set Up Environment Variables Source: https://developers.forem.com/getting-started/installation/linux Copies the environment variable sample file to '.env' and exports necessary API keys for services like Cloudinary. This file is personal and ignored by git. Real keys are not always required for basic development. ```bash cp .env_sample .env export CLOUDINARY_API_KEY="SOME_REAL_SECURE_KEY_HERE" export CLOUDINARY_API_SECRET="ANOTHER_REAL_SECURE_KEY_HERE" export CLOUDINARY_CLOUD_NAME="A_CLOUDINARY_NAME" ``` -------------------------------- ### Start Imgproxy Server Source: https://developers.forem.com/getting-started/installation/imgproxy Commands to launch the Imgproxy server using either a local binary or a containerized environment (Docker/Podman) with the generated credentials. ```bash # If you installed via homebrew or using the binary. IMGPROXY_KEY='your key' IMGPROXY_SALT='your salt' imgproxy # If you are using Docker or Podman. docker run -p 8080:8080 \ -e IMGPROXY_KEY="your key" \ -e IMGPROXY_SALT="your salt" \ -it darthsim/imgproxy ``` -------------------------------- ### Configure PostgreSQL User and Database Source: https://developers.forem.com/getting-started/installation/windows Commands to initialize a PostgreSQL user and database on a Linux system. This process requires an active PostgreSQL service and replaces the placeholder username with the current system user. ```bash sudo -u postgres createuser -s $YOUR_USERNAME createdb sudo -u $YOUR_USERNAME psql ``` -------------------------------- ### Interact with Vault Secrets in Rails Console Source: https://developers.forem.com/getting-started/installation/vault Ruby code examples demonstrating how to set and retrieve secrets using the AppSecrets interface within a Rails console. It also shows the Vault::MissingTokenError when Vault is not properly configured. ```ruby # Enabled Example [3] pry(main)> AppSecrets["TEST_SET"]="success" => "success" [4] pry(main)> AppSecrets["TEST_SET"] => "success" # Disabled Example [2] pry(main)> AppSecrets["TEST_SET"]="success" Vault::MissingTokenError: Missing Vault token! I cannot make requests to Vault without a token. Please set a Vault token in the client: Vault.token = "1234" or authenticate with Vault using the Vault CLI: $ vault auth ... or set the environment variable $VAULT_TOKEN to the token value: $ export VAULT_TOKEN="..." Please refer to the documentation for more examples. ``` -------------------------------- ### Install Yarn on Debian/Ubuntu without Node.js Source: https://developers.forem.com/getting-started/installation/windows Installs the Yarn package manager from the configured Debian repository. This command is used when Node.js is not yet installed, as Yarn can be installed independently. ```bash sudo apt update && sudo apt install --no-install-recommends yarn ``` -------------------------------- ### Install Ruby Dependencies for rbenv on Ubuntu Source: https://developers.forem.com/getting-started/installation/windows Installs essential Ruby language dependencies required before installing the rbenv version manager. This command updates the package list and installs development libraries for Ruby. ```bash sudo apt-get update sudo apt-get install git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev software-properties-common libffi-dev ``` -------------------------------- ### Clone Forem Repository using Git Source: https://developers.forem.com/getting-started/installation/linux Clones the Forem repository from GitHub. Users can choose between HTTPS or SSH for cloning. Cloning is necessary for reading the code and required for submitting changes. ```bash git clone https://github.com//forem.git ``` ```bash git clone git@github.com:/forem.git ``` -------------------------------- ### Build Ruby source code documentation Source: https://developers.forem.com/FAQ/faqs Instructions for generating local Ruby documentation using the make utility within the project's documentation directory. ```shell cd docs make ruby-doc ``` -------------------------------- ### POST /display_ads Source: https://developers.forem.com/api/v1 Creates a new display ad. Requires an API key. ```APIDOC ## POST /display_ads ### Description This endpoint allows the client to create a new display ad. Requires API key authorization. ### Method POST ### Endpoint https://dev.to/api/display_ads ### Request Body - **payload** (object) - Required - Ad configuration data. ### Response #### Success Response (200) - **id** (integer) - The ID of the created ad. - **name** (string) - The name of the ad. #### Response Example { "id": 193, "name": "Example Ad", "approved": true } ``` -------------------------------- ### Serve API documentation locally Source: https://developers.forem.com/contributing-guide/api Starts a local development server to preview the auto-generated API documentation. The server supports hot-reloading whenever the underlying specification file is modified. ```bash yarn api-docs:serve ``` -------------------------------- ### Configure Yarn Repository on Debian/Ubuntu Source: https://developers.forem.com/getting-started/installation/windows Adds the Yarn Debian package repository to the system's sources list. This involves importing the GPG key and creating a new sources list file. ```bash curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add - echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list ``` -------------------------------- ### AuditLog Record Example Source: https://developers.forem.com/backend/audit-log An example of an AuditLog record, showcasing the structure and information captured for a specific user action. This includes details like the category, timestamps, data associated with the action, user roles, and the user ID. ```ruby #"create", "category"=>"vomit", "controller"=>"reactions", "reactable_id"=>"16", "reactable_type"=>"Article"}, roles: ["trusted"], slug: "create", updated_at: Thu, 07 May 2020 20:25:31 UTC +00:00, user_id: 21> ``` -------------------------------- ### Get Podcast Episodes (GET /podcast_episodes) Source: https://developers.forem.com/api/v1 Retrieves a list of active podcast episodes, ordered by publication date. Supports pagination and filtering by podcast username. Returns a list of podcast episode objects or a 404 if the username is not found. ```json [ { "type_of": "podcast_episodes", "class_name": "PodcastEpisode", "id": 4, "path": "/codenewbie/slug-4", "title": "5", "image_url": "/uploads/podcast/image/8/624a3c09-8036-43e4-9187-4cbf6d3c1fd6.jpeg", "podcast": { "title": "Maudite", "slug": "codenewbie", "image_url": "/uploads/podcast/image/8/624a3c09-8036-43e4-9187-4cbf6d3c1fd6.jpeg" } } ] ```