FreeBSD 14
Sponsored Link

Ruby on Rails 7 : Install2024/08/23

 

Install Ruby on Rails 7 to build Ruby Framework environment.

[1]

Install Ruby, refer to here.

[2] Install some other required packages.
root@dlp:~ #
pkg install -y devel/ruby-gems yarn libxml2 libxslt libyaml node20 git
[3] Install Rails 7.
root@dlp:~ #
gem install bundler

root@dlp:~ #
gem install rails -N --version='~> 7.0, < 8.0'

root@dlp:~ #
rails -v

Rails 7.2.1
[4] Create a sample application and make sure it works normally.
Install MariaDB Server for this sample app, refer to here.
# create database and user for sample application

root@dlp:~ #
mysql

Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 9
Server version: 10.11.8-MariaDB FreeBSD Ports

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> create database sample_app_test; 
Query OK, 1 row affected (0.000 sec)

MariaDB [(none)]> create database sample_app_development; 
Query OK, 1 row affected (0.000 sec)

MariaDB [(none)]> grant all privileges on sample_app_test.* to serverworld@'localhost' identified by 'password'; 
Query OK, 0 rows affected (0.005 sec)

MariaDB [(none)]> grant all privileges on sample_app_development.* to serverworld@'localhost' identified by 'password'; 
Query OK, 0 rows affected (0.005 sec)

MariaDB [(none)]> exit 
Bye

root@dlp:~ #
gem install mysql2 -- --with-mysql-config=/usr/local/bin/mysql_config

root@dlp:~ #
rails new SampleApp -d mysql

root@dlp:~ #
cd SampleApp

root@dlp:~/SampleApp#
vi config/database.yml
default: &default
  adapter: mysql2
  encoding: utf8mb4
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  username: serverworld     # MariaDB connection user
  password: password        # MariaDB connection password
  host: localhost

root@dlp:~/SampleApp#
vi config/application.rb
module SampleApp
  class Application < Rails::Application
    # Initialize configuration defaults for originally generated Rails version.
    config.load_defaults 7.2
    # line 13 : specify hosts
    # if not specified, users can access to only [localhost] and IP address
    # if allow all sub-domain, specify domain name like follows
    config.hosts << ".srv.world" 

# create sample application

root@dlp:~/SampleApp#
rails generate scaffold testapp name:string title:string body:text

root@dlp:~/SampleApp#
rails db:migrate

== 20240823002521 CreateTestapps: migrating ===================================
-- create_table(:testapps)
   -> 0.0101s
== 20240823002521 CreateTestapps: migrated (0.0108s) ==========================

root@dlp:~/SampleApp#
rails server --binding=0.0.0.0

=> Booting Puma
=> Rails 7.2.1 application starting in development
=> Run `bin/rails server --help` for more startup options
Puma starting in single mode...
* Puma version: 6.4.2 (ruby 3.2.4-p170) ("The Eagle of Durango")
*  Min threads: 3
*  Max threads: 3
*  Environment: development
*          PID: 12444
* Listening on http://0.0.0.0:3000
Use Ctrl-C to stop
[5] Access to the [http://(server's hostname or IP address):3000/] from a client computer. It's OK if following site is displayed normally.
  Access to [http://(server's hostname or IP address):3000/testapps], then it's possible to use sample app like follows.
Matched Content