Tuesday, June 13, 2023

HOW TO USE TRIX-EDITOR

Trix is an editor for writing messages, comments, articles, and lists—the simple documents most web apps are made of. It features a sophisticated document model, support for embedded attachments, and outputs terse and consistent HTML.


$  rails new trix_editor --css tailwind

$  cd trix_editor

$  rails action_text:install

$  rails g scaffold post title content:rich_text

$  rails s



Thursday, June 8, 2023

Fix Ubuntu on WSL that failed to boot after reinstalling

When you reinstall Ubuntu on WSL (Windows Subsystem for Linux), you might encounter an error message preventing the system from booting.

eg: Failed to attach disk 'C:\Users\ahaya\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu_79rhkp1fndgsc\LocalState\ext4.vhdx' to WSL2: The specified file could not be found.
Error code: Wsl/Service/CreateInstance/MountVhd/ERROR_FILE_NOT_FOUND
Failed to attach disk 'C:\Users\ahaya\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu_79rhkp1fndgsc\LocalState\ext4.vhdx' to WSL2: The specified file could not be found.
Error code: Wsl/Service/CreateInstance/MountVhd/ERROR_FILE_NOT_FOUND
Failed to attach disk 'C:\Users\ahaya\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu_79rhkp1fndgsc\LocalState\ext4.vhdx' to WSL2: The specified file could not be found.
Error code: Wsl/Service/CreateInstance/MountVhd/ERROR_FILE_NOT_FOUND
Press any key to continue...

1. Launch Windows PowerShell (No Need Administrator)

2. Run "wsl -l" in PowerShell to get the registered distribution

eg: PS C:\Users\Name> wsl -l
Windows Subsystem for Linux Distributions:
Ubuntu (Default)

3. Unregister Ubuntu.

Run wsl --unregister Ubuntu in PowerShell to unregister Ubuntu.

eg: PS C:\Users\User> wsl --unregister Ubuntu
Unregistering.
The operation completed successfully.

4. Launch Ubuntu and perform the initialization process.

The initialization process begins when you launch Ubuntu after it has been unregistered. After that, you can create an Ubuntu account as follows.

eg: Installing, this may take a few minutes...
Please create a default UNIX user account. The username does not need to match your Windows username.
For more information visit: https://aka.ms/wslusers
Enter new UNIX username:

Source: https://www.en.techgaku.com/fix-ubuntu-boot-error-on-wsl-after-reinstall/

Wednesday, February 15, 2023

HOW TO USE DEVISE GEM

$ rails new devise_app -j esbuild -css bootstrap


$ cd devise_app


$ bundle add devise


$ rails g devise:install


$ rails g devise User


$ rails g controller pages home


$ rails db:migrate


[config/routes.rb]
root 'pages#home'


[app/views/pages/home.html.erb]

<% if current_user %>
    <p>Logged in as <%= current_user.email %></p>
    <%= link_to "Logout", destroy_user_session_path, method: :delete, data: { turbo_method: :delete } %>
<% else %>
    <%= link_to "Login", new_user_session_path %>
    <%= link_to "Sign up", new_user_registration_path %>
<% end %>

🐞Source: devise

Friday, December 16, 2022

VS Code Editor

 Download VS Code Editor: Here

VS Code Extensions

Recommended

1. esbenp.prettier-vscode

2. formulahendry.auto-close-tag

3. hex-ci.stylelint-plus

4. dbaeumer.vscode-eslint

5. naumovs.color-highlight

6. DigitalBrainstem.javascript-ejs-support

Optional

7. ritwickdey.LiveServer

8. erikphansen.vscode-toggle-column-selection

9. vscode-icons

10. Auto Rename Tag


VS Code Extensions for Rails

1. VS Code Icons

2. GitHub Copilot

3. TabNine AI Autocomplete

4. Ruby

5. VSCode Ruby (Syntax Highlighting)

6. ERB Formatter

7. Prettier



Wednesday, July 13, 2022

How to install Rspec

Add rspec-rails to both the :development and :test groups of your app’s Gemfile:

# Run against this stable release
group :development, :test do
  gem 'rspec-rails', '~> 6.0.0'
end

# Download and install
$ bundle install

# Generate boilerplate configuration files
# (check the comments in each generated file for more information)
$ rails generate rspec:install
      create  .rspec
      create  spec
      create  spec/spec_helper.rb
      create  spec/rails_helper.rb

$ rails generate respec:model user
# Running spec
$ bundle exec rspec spec/models (Run all spec files)
$ bundle exec rspec spec/models/user_spec.rb (Run a single spec file)

$ rails generate rspec:system users
# Running spec
$ bundle exec rspec spec/system/users_spec.rb

Source: rspec-rails

Tip: ※$ rails generate

Wednesday, June 1, 2022

How to fix Yarn packages are out of date in terminal

 =====================================

  Your Yarn packages are out of date!

  Please run 'yarn install --check-files' to update.

=====================================


1. Delete node_modules

$ rm -rf node_modules


2. Delete yarn.lock file

$ rm -rf yarn.lock


3. Install yarn

$ yarn install


4. Upgrade yarn

$ yarn upgrade


5. Run server

$ rails s

Tuesday, May 31, 2022

HEROKU CHEATSHEET

Install Heroku CLI

For macOS

$ brew tap heroku / brew && brew install heroku

For Windows

$ wget -qO- https://cli-assets.heroku.com/install-ubuntu.sh | sh


Heroku Command

$ git add -A

$ git commit -m "initial commit"

$ git push heroku master

$ heroku run rails db:migrate

How to Login Heroku

$ heroku login -i (for windows)

$ heroku login (for Mac)

Create an app

$ heroku init (if you need)

$ heroku create OR heroku create sushi

Show logs

$ heroku logs

$ heroku logs -t      # --tail (stream)

$ heroku logs -s app    # --source (only on app logs)

Configuration

$ heroku config # List

$ heroku config -s # List in shell format

Restart

$ heroku restart

$ heroku pg:reset DATABASE

PostgreSQL

$ heroku addons:add heroku-postgresql (Start a database)

Applications

$ heroku apps # list

$ heroku apps:create [NAME]

$ heroku apps:destroy --app APPNAME

$ heroku apps:info

$ heroku apps:open # open in browser

$ heroku apps:rename NEWNAME