Next, we exclude the columns that represent timestamps. The above first creates a new menu tab and names it VIP Clients. We can use the following code in clients.rb to clean and tailor it to our needs: Our dashboard interface looks a bit cluttered and has a lot of information, some of which we don't need readily available. Now that we have a dashboard, let's look at how to edit the UI. Our dashboard with the data seeded from the Faker gem should look like this: Step 8: Edit the UI The rails db:reset command combines db:drop, db:create, and db:migrate and is a useful method for cleaning up the database. Note: It's good practice to occasionally call rails db:reset before db:seed. Once you've entered this code, run rails db: reset, then rails db:seed, restart the server, and navigate to the admin page at localhost:3000/admin. There are also simple status messages at the beginning and end of the operation to help the user track. Note that the destroy_all method is dangerous, and you should be careful when using it on a production database (we're just using this for our sample dashboard). We call stroy_all at the beginning to ensure that old entries in the database are deleted and recreated each time the database is dropped. The above code uses the create! method, which throws an error if the operation fails. For simplicity, we'll restrict the number of entries on the list to ten.Įnter the following code into the seeds.rb file to generate the data: Each individual on our client list works for a company and has a name, address, and phone number. We'll create a list of clients for this application that mirrors the model generated earlier. Faker is a library for generating random data and is much more convenient than writing everything manually. Next, let's add some data since our application is up and running without data. The Comments menu item is also important, as it lets users add more information to an object (in this case, a client) and is useful for adding descriptions, tracking issues, and so on. Clicking this tab opens a separate dashboard. The main dashboard should now have a new Clients tab that was created by Active Admin after you registered the Client model as a resource. You've now successfully set up Active Admin in a Ruby on Rails application! If you navigate to localhost:3000/admin, your dashboard should look similar to the following screenshot: To get started, create a new application using the rails new command: sassc-rails version 2.1 (later versions should also work).devise version 4.8 (later versions should also work).This demo app is built using Ruby 3.1.2 and Rails 7.0.4. Set up CRUD operations and strong parametersīefore getting started with this tutorial, please ensure you have the following prerequisites:.In order to simplify the process, we break it down into the following steps: In this tutorial, we'll walk through how to build a dashboard using Active Admin. Build a dashboard using Ruby's Active Admin It also grants the user the ability to export data in CSV, XML, and JSON format. You can also enforce access controls at various levels and grant users permission to view or alter certain information.Īctive Admin is useful because it also has built-in functionality for authentication as well as for searching and filtering data. You can then analyze the data to reveal relationships between attributes of the underlying model or between models of the schema. Developers use it to quickly set up data in their applications or to allow other team members to view application data. What is Active Admin?Īctive Admin is popular in the Rails community because it provides a convenient way to structure and present information. We'll also show you how to carry out basic tasks like seeding the database, connecting a model, editing the UI, setting up CRUD operations, and exporting internal data to an external file in CSV format.Īt the end, we'll discuss some pros and cons of Active Admin and introduce Airplane, a developer platform for rapidly building internal UIs and Workflows, as an alternative solution for developing custom interfaces. In this article, we'll walk through how to get started with Active Admin by building a simple dashboard. It provides a convenient way to structure and present internal data, and it's packaged as a Ruby gem that may be downloaded for use in Rails applications. Active Admin is a Ruby on Rails plug-in used to create simple dashboards and administrative interfaces.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |