Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
61ef30d
wrote blog for postman
Nov 26, 2021
a7241ad
Merge branch 'EndPointCorp:main' into master
Jan 4, 2022
eeb7fa5
Merge branch 'EndPointCorp:main' into master
Couragyn Oct 18, 2023
19c18b7
adding my jsforce blogpost
Oct 18, 2023
7a91d93
fixes for merge. moved new blogpost .md out of subfolder. Removed old…
Oct 18, 2023
2d7aed2
added ref to Dylans deeper post. Changed incorrect info that its java…
Oct 18, 2023
9f5cf48
changed first part to talk about what Apex is and why JS might be a g…
Oct 19, 2023
75b5731
fixed lint issues
Oct 19, 2023
8bc0452
fixed typo
Oct 19, 2023
49c6984
fix merge"
Mar 6, 2025
233ec8a
added blog post Understanding the Relationship Between Apex and Sales…
Mar 6, 2025
92757b5
changed code block format
Mar 6, 2025
815fc2e
added : in code block
Mar 6, 2025
d2615fe
added linebreak in code blocks
Mar 6, 2025
8025bd8
changed code block language
Mar 6, 2025
050500a
fixed merge issue on my old post
Mar 6, 2025
e150f38
Update understanding_the_relationship_between_apex_and_salesforce.md
Couragyn Mar 12, 2025
bb88b57
Merge branch 'EndPointCorp:main' into master
Couragyn Jul 21, 2025
efe45a1
Merge branch 'EndPointCorp:main' into master
Couragyn Nov 27, 2025
d4c1ffa
Blog post for Using ActiveSupport::ExecutionContext to improve Rails …
Nov 27, 2025
29dc60f
cleaning up pr
Nov 27, 2025
38e0792
cleaning up for pr
Nov 27, 2025
964f862
one more try to try and remove non change for jsforce-quick-path-to-s…
Nov 27, 2025
0dadaf7
blog post for Quick and Dirty Admin Pages with Rails scaffold_controller
Nov 27, 2025
972c556
cleanup for PR
Nov 27, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion 2023/10/jsforce-quick-path-to-salesforce-development.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,4 @@ conn.sobject("Account").destroy('0017000000hOMChAAO', function(err, ret) {
});
```

For a deeper dive into setup and uses of JSforce check out [this post](/blog/2020/03/salesforce-integration-with-node/) by my coworker Dylan Wooters.
For a deeper dive into setup and uses of JSforce check out [this post](/blog/2020/03/salesforce-integration-with-node/) by my coworker Dylan Wooters.
118 changes: 118 additions & 0 deletions 2025/12/quick_admin_pages_with_rails_scaffold.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
---
title: "Quick and Dirty Admin Pages with Rails scaffold_controller"
author: Couragyn Chretien
date: 2025-12-01
description: Build admin interfaces fast with Rails' scaffold_controller generator. Skip heavy gems and create full CRUD controllers/views for existing models in minutes. Perfect for internal tools and prototypes.
tags:
- rails
- admin
- scaffold_controller
- quick and dirty
---

## Quick and Dirty Admin Pages with Rails scaffold_controller
You're building a Rails application, and you've reached that point where you or your team needs a simple way to manage data. You need an admin interface. You've heard of heavy-weight solutions like ActiveAdmin or Rails Admin, but they feel like overkill for adding a few new categories or moderating user posts. You don't want to spend an afternoon configuring a gem. You need something now.

Luckily Rails has a built-in lightning-fast way to generate a fully functional admin CRUD interface for any existing model. Meet the often-overlooked scaffold_controller generator. It's the secret weapon for building "quick and dirty" internal tools.

### What is scaffold_controller and why Use It?
When you run `rails generate scaffold Post`, it creates everything: the model, migration, controller, and views. The scaffold_controller generator does only half of that, it creates just the controller and views (as long as the model already exists).

This is perfect for creating a separate admin namespace because:
- **It's Non-Destructive:** Your existing, user-facing PostsController remains untouched.
- **It's Fast:** One command gives you a complete set of CRUD actions and ERB views.
- **It's Simple:** No new gems, dependencies, or complex configurations to learn.

### Let's Build an Admin Interface for a Product Model
Imagine you have a Product model in your application. You have a ProductsController for your main site, but now you need an admin area to create, edit, and delete products.

#### Step 1: Create the Admin Namespace and Route

First, we'll set up a routing namespace to keep our admin logic separate. This will put our URLs in this format: `/admin/products`

Open your `config/routes.rb` file and add:

ruby
# config/routes.rb
Rails.application.routes.draw do
# ... existing routes ...

namespace :admin do
resources :products
end
end
Running `rails routes` will now show new routes like `admin_products_path`, `edit_admin_product_path`, etc.

#### Step 2: Generate the Scaffold Controller

Now for the magic. In your terminal, run `rails generate scaffold_controller Admin::Product`

Important Notes:
- The namespace (Admin::) must match the one you used in your routes.
- The model name (Product) must be singular, just like with a regular scaffold.

This one command generates several files:
- **Controller:** `app/controllers/admin/products_controller.rb`
- **Views:** A full set of ERB templates in `app/views/admin/products/` (`index.html.erb`, `show.html.erb`, `new.html.erb`, `edit.html.erb`, `_form.html.erb`)

#### Step 3: Update the generated Controller

The generated controller is a great start but it needs one crucial tweak. It doesn't know about our namespace, so it will look for the Product model in the wrong place. The key change is ensuring every reference to the model is to Product, not Admin::Product.

Open the products_controller.r and change the class definition and any model references. Here's a simplified example of what it should look like:

```ruby
# app/controllers/admin/products_controller.rb
module Admin
class ProductsController < ApplicationController
before_action :set_product, only: [:show, :edit, :update, :destroy]

# GET /admin/products
def index
@products = Product.all
end

# ... other actions ...

private
def set_product
@product = Product.find(params[:id])
end

def product_params
params.require(:product).permit(:name, :description, :price, :stock)
end
end
end
```

#### Step 4: Add a Link and Access Control

Your admin interface is now live at `http://localhost:3000/admin/products`. Before you deploy you must add some form of access control. This can be as simple as a basic HTTP authentication check in your Admin::ProductsController.

```ruby
# app/controllers/admin/products_controller.rb
module Admin
class ProductsController < ApplicationController
http_basic_authenticate_with name: ENV['ADMIN_USER'], password: ENV['ADMIN_PASSWORD']

# ... rest of the controller code ...
end
end
```

It would also be good to add a link in your navigation for easy access:
`<%= link_to "Admin Products", admin_products_path if Rails.env.development? %>`

### When Should You Use This Method?
**Ideal for:**
- Internal tools, administrative, and support functions.
- Rapid prototyping.
- Simple CRUD needs where a full-blown admin gem is overkill.

**Not ideal for:**
- Customer-facing admin panels that need complex filtering, dashboards, or custom forms.
- Applications where you need fine-grained, role-based permissions.

### Conclusion
The scaffold_controller generator is a fantastic piece of Rails tooling that is often overlooked. It embodies the Rails philosophy of providing quick solutions for common problems. In just a few minutes you can have a functional, separate admin area for any model without the overhead of a new gem or the risk of breaking your public-facing code. So next time you need a simple data management interface, skip the gem research and let scaffold_controller do the heavy lifting for you.