Skip to content

qisantanu/hotwired_app

Repository files navigation

Hotwire Logo

Hotwired Application

This is a Rails application to play with different features of HTML Over the Wire.

Pre-requisites

The following software is required to work with the repository. This project currently works with:

Ruby version Rails Bundler Postgres Database Solid Queue

Setup

  1. bundle install
  2. rails importmap:install
  3. rails turbo:install stimulus:install
  4. rails db:create; db:seed
  5. Open rails console and run Developer.insert_fake_data 20
  6. Solid Queue is configured by default in new Rails 8 applications. But if you're running an earlier version, you can add it manually following these steps:
  • bundle add solid_queue
  • bin/rails solid_queue:install
  1. To run the backend worker: bin/jobs || bundle exec rake solid_queue:start

Importmap setup

Example: Add jQuery to the application

  1. First we need to create ImportMap for jQuery
  2. Run bin/importmap pin jquery
  3. This adds the jQuery library and its dependencies to the config/importmap.rb file. Note that we’re using a CDN location for the jQuery library, which grants access to the entire NPM catalog via Import Maps without requiring Node.js for package compilation.
  4. Now to add JQuery:
      import jQuery from "jquery";
      jQuery('body').css('background-color', '#f2f2f2');
      // This is how the jQuery works
      // You need to import like above
      // And then use that instead of '$'
  5. You will get some idea in : https://github.com/qisantanu/hotwired_app/pull/24/files

Additional information

For creating modal controller the command used

rails g stimulus turbomodal

The controller nme of timulus should be a word like 'notification', 'pagination' I have tried with 'notification_scroll' which is not working, may be the snake case is not valid.

For creating the fake data

  1. Developer.insert_fake_data
  2. Notification.bulk_create_for_testing
  3. Notification.fake_notification_stream

Features covered

  1. Lazy loading using Hotwire
  2. Modal form open for the Create. Update Operation
  3. Custom pagination using Hotwire
  4. Sorting the data using Hotwire
  5. Integrate FontAwesome with the application
  6. Append, Update or Delete from HTML view via the Active record transaction callback
  7. Infinite scroll

In-Code Documentation with Yard

This project utilises Yard for in-code documentation. Yard is a documentation generation tool for Ruby that provides a clean and consistent way to document your code.

Setting Up Yard

To generate and view the documentation locally, follow these steps:

  1. Install Yard: It is part of the Gemfile in the development environment, after the bundle install, it is ready to be used.
  2. Generate Documentation: Run the following command to generate documentation for your project: yar -o docs This will create a docs directory with the generated documentation.
  3. View Documentation Locally: - Open the doc/index.html file in your browser to browse the documentation. Or you can start the Yard server locally and access the documents.

Additional Yard Configuration

You can customize Yard's behaviour by adding a .yardopts file in the root of your project. This file can contain various options and flags to control the documentation generation process. Refer to the Yard documentation for more details.

About

Hotwire and Stimulus to build a CRUD functionality

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published