solidcrud 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE +21 -0
- data/README.md +1285 -0
- data/app/assets/javascripts/controllers/dashboard_controller.js +96 -0
- data/app/assets/javascripts/controllers/modal_controller.js +217 -0
- data/app/assets/javascripts/controllers/navigation_controller.js +117 -0
- data/app/assets/javascripts/controllers/notification_controller.js +85 -0
- data/app/assets/javascripts/controllers/search_controller.js +189 -0
- data/app/assets/javascripts/controllers/table_controller.js +272 -0
- data/app/assets/javascripts/solidcrud/application.js +9475 -0
- data/app/assets/stylesheets/solidcrud/_components.scss +267 -0
- data/app/assets/stylesheets/solidcrud/_forms.scss +69 -0
- data/app/assets/stylesheets/solidcrud/_layout.scss +149 -0
- data/app/assets/stylesheets/solidcrud/_tables.scss +90 -0
- data/app/assets/stylesheets/solidcrud/_variables.scss +21 -0
- data/app/assets/stylesheets/solidcrud/application.css +10 -0
- data/app/assets/stylesheets/solidcrud/application.css.map +1 -0
- data/app/assets/stylesheets/solidcrud/application.scss +10 -0
- data/app/assets/stylesheets/solidcrud/temp.css.map +1 -0
- data/app/assets/stylesheets/solidcrud/temp2.css.map +1 -0
- data/app/assets/stylesheets/solidcrud/webfonts/fa-brands-400.ttf +0 -0
- data/app/assets/stylesheets/solidcrud/webfonts/fa-brands-400.woff2 +0 -0
- data/app/assets/stylesheets/solidcrud/webfonts/fa-regular-400.ttf +0 -0
- data/app/assets/stylesheets/solidcrud/webfonts/fa-regular-400.woff2 +0 -0
- data/app/assets/stylesheets/solidcrud/webfonts/fa-solid-900.ttf +0 -0
- data/app/assets/stylesheets/solidcrud/webfonts/fa-solid-900.woff2 +0 -0
- data/app/assets/stylesheets/solidcrud/webfonts/fa-v4compatibility.ttf +0 -0
- data/app/assets/stylesheets/solidcrud/webfonts/fa-v4compatibility.woff2 +0 -0
- data/app/assets/stylesheets/webfonts/fa-brands-400.ttf +0 -0
- data/app/assets/stylesheets/webfonts/fa-brands-400.woff2 +0 -0
- data/app/assets/stylesheets/webfonts/fa-regular-400.ttf +0 -0
- data/app/assets/stylesheets/webfonts/fa-regular-400.woff2 +0 -0
- data/app/assets/stylesheets/webfonts/fa-solid-900.ttf +0 -0
- data/app/assets/stylesheets/webfonts/fa-solid-900.woff2 +0 -0
- data/app/assets/stylesheets/webfonts/fa-v4compatibility.ttf +0 -0
- data/app/assets/stylesheets/webfonts/fa-v4compatibility.woff2 +0 -0
- data/app/controllers/solidcrud/admin_controller.rb +215 -0
- data/app/controllers/solidcrud/application_controller.rb +19 -0
- data/app/controllers/solidcrud/assets_controller.rb +59 -0
- data/app/controllers/solidcrud/sessions_controller.rb +84 -0
- data/app/helpers/solidcrud/application_helper.rb +153 -0
- data/app/javascript/solidcrud/application.js +14 -0
- data/app/javascript/solidcrud/controllers/crud_controller.js +64 -0
- data/app/javascript/solidcrud/controllers/index.js +33 -0
- data/app/views/layouts/solidcrud/application.html.erb +70 -0
- data/app/views/solidcrud/admin/edit.html.erb +294 -0
- data/app/views/solidcrud/admin/index.html.erb +128 -0
- data/app/views/solidcrud/admin/model.html.erb +353 -0
- data/app/views/solidcrud/admin/new.html.erb +275 -0
- data/app/views/solidcrud/admin/shared/_dashboard_stats.html.erb +49 -0
- data/app/views/solidcrud/admin/shared/_edit_form_sidebar.html.erb +9 -0
- data/app/views/solidcrud/admin/shared/_flash_messages.html.erb +27 -0
- data/app/views/solidcrud/admin/shared/_full_sidebar.html.erb +56 -0
- data/app/views/solidcrud/admin/shared/_modal.html.erb +45 -0
- data/app/views/solidcrud/admin/shared/_new_form_sidebar.html.erb +6 -0
- data/app/views/solidcrud/admin/shared/_record_row.html.erb +35 -0
- data/app/views/solidcrud/admin/shared/_records_table.html.erb +85 -0
- data/app/views/solidcrud/sessions/new.html.erb +262 -0
- data/config/routes.rb +24 -0
- data/lib/generators/solidcrud/install/install_generator.rb +21 -0
- data/lib/generators/solidcrud/install/templates/INSTALL.md +80 -0
- data/lib/generators/solidcrud/install/templates/solidcrud.rb +31 -0
- data/lib/generators/solidcrud/install_generator.rb +17 -0
- data/lib/generators/solidcrud/templates/solidcrud.rb +4 -0
- data/lib/solidcrud/authentication.rb +143 -0
- data/lib/solidcrud/configuration.rb +64 -0
- data/lib/solidcrud/engine.rb +49 -0
- data/lib/solidcrud/version.rb +5 -0
- data/lib/solidcrud.rb +10 -0
- metadata +177 -0
data/README.md
ADDED
|
@@ -0,0 +1,1285 @@
|
|
|
1
|
+
# SolidCRUD ๐
|
|
2
|
+
|
|
3
|
+
[](https://badge.fury.io/rb/solidcrud)
|
|
4
|
+
[](https://rubyonrails.org)
|
|
5
|
+
[](LICENSE)
|
|
6
|
+
|
|
7
|
+
A zero-configuration admin dashboard for Rails 6, 7, and 8. Get a fully functional admin interface in under 30 seconds - no configuration required!
|
|
8
|
+
|
|
9
|
+
## ๐ Getting Started
|
|
10
|
+
|
|
11
|
+
### Installation
|
|
12
|
+
|
|
13
|
+
Add SolidCRUD to your Rails application's Gemfile:
|
|
14
|
+
|
|
15
|
+
```ruby
|
|
16
|
+
gem 'solidcrud', path: 'path/to/solidcrud'
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Then run:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
bundle install
|
|
23
|
+
rails solidcrud:install
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### JavaScript & Asset Setup
|
|
27
|
+
|
|
28
|
+
SolidCRUD includes modern JavaScript, Tailwind CSS, and Sass assets. Install dependencies and build assets:
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
# Install JavaScript dependencies
|
|
32
|
+
npm install
|
|
33
|
+
|
|
34
|
+
# Build assets for production
|
|
35
|
+
npm run build
|
|
36
|
+
|
|
37
|
+
# Or build and watch for development
|
|
38
|
+
npm run build:watch
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
The build process:
|
|
42
|
+
- **JavaScript**: Bundles Stimulus controllers and application code with esbuild
|
|
43
|
+
- **CSS**: Processes Tailwind CSS with PostCSS, includes custom components and utilities
|
|
44
|
+
|
|
45
|
+
#### Included Dependencies
|
|
46
|
+
|
|
47
|
+
- **@hotwired/stimulus** (^3.2.2) - For interactive UI components
|
|
48
|
+
- **@hotwired/turbo-rails** (^8.0.12) - For seamless page updates
|
|
49
|
+
- **jquery** (^3.7.0) - For legacy compatibility
|
|
50
|
+
- **tailwindcss** (^3.4.0) - For modern utility-first CSS
|
|
51
|
+
- **esbuild** (^0.25.0) - For fast JavaScript bundling
|
|
52
|
+
- **sass** (^1.63.6) - For CSS preprocessing
|
|
53
|
+
- **autoprefixer** (^10.4.16) - For CSS vendor prefixes
|
|
54
|
+
- **postcss** (^8.4.32) - For CSS processing
|
|
55
|
+
|
|
56
|
+
### Basic Configuration
|
|
57
|
+
|
|
58
|
+
Configure SolidCRUD in `config/initializers/solidcrud.rb`:
|
|
59
|
+
|
|
60
|
+
```ruby
|
|
61
|
+
Solidcrud.setup do |config|
|
|
62
|
+
# Configure your models
|
|
63
|
+
config.models = ['User', 'Post', 'Comment']
|
|
64
|
+
|
|
65
|
+
# Set authentication (see Authentication section below)
|
|
66
|
+
config.authenticate_with do
|
|
67
|
+
# Your authentication logic
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
- **๐ฅ Zero Configuration**: Works out of the box with any Rails app
|
|
73
|
+
- **๐ฑ Responsive Design**: Modern Bootstrap 5 UI that works on all devices
|
|
74
|
+
- **๐ Smart Search**: Automatically searches across text columns
|
|
75
|
+
- **๐ Sortable Tables**: Click any column header to sort
|
|
76
|
+
- **๐ Pagination**: Handles large datasets with elegant pagination
|
|
77
|
+
- **๐จ Intelligent Forms**: Auto-detects field types (email, phone, date, etc.)
|
|
78
|
+
- **๐ Model Detection**: Automatically discovers all ActiveRecord models
|
|
79
|
+
- **โก Fast Setup**: Add gem โ run generator โ visit /admin
|
|
80
|
+
- **๐๏ธ Configurable**: Hide models or customize behavior as needed
|
|
81
|
+
|
|
82
|
+
## ๐ Installation & Setup
|
|
83
|
+
|
|
84
|
+
### Prerequisites
|
|
85
|
+
|
|
86
|
+
Before installing SolidCRUD, ensure you have:
|
|
87
|
+
|
|
88
|
+
- **Ruby**: 2.7 or higher
|
|
89
|
+
- **Rails**: 6.0 or higher (including Rails 8.x)
|
|
90
|
+
- **Database**: Any ActiveRecord-supported database (SQLite, PostgreSQL, MySQL, etc.)
|
|
91
|
+
- **Node.js & Yarn**: For asset compilation (if using Webpacker/Propshaft)
|
|
92
|
+
|
|
93
|
+
### Step 1: Add SolidCRUD to Your Gemfile
|
|
94
|
+
|
|
95
|
+
Add the gem to your Rails application's `Gemfile`:
|
|
96
|
+
|
|
97
|
+
```ruby
|
|
98
|
+
# Gemfile
|
|
99
|
+
gem 'solidcrud'
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### Step 2: Install Dependencies
|
|
103
|
+
|
|
104
|
+
Run bundle install to install the gem and its dependencies:
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
bundle install
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### Step 3: Run the Installation Generator
|
|
111
|
+
|
|
112
|
+
SolidCRUD includes an installation generator that sets up the necessary configuration:
|
|
113
|
+
|
|
114
|
+
```bash
|
|
115
|
+
rails generate solidcrud:install
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
This generator will:
|
|
119
|
+
- Create `config/initializers/solidcrud.rb` (optional configuration file)
|
|
120
|
+
- Display setup completion message
|
|
121
|
+
|
|
122
|
+
### Step 4: Mount the Engine Routes
|
|
123
|
+
|
|
124
|
+
Add the SolidCRUD routes to your `config/routes.rb`:
|
|
125
|
+
|
|
126
|
+
```ruby
|
|
127
|
+
# config/routes.rb
|
|
128
|
+
Rails.application.routes.draw do
|
|
129
|
+
# ... your existing routes ...
|
|
130
|
+
|
|
131
|
+
# Mount SolidCRUD admin interface
|
|
132
|
+
mount Solidcrud::Engine => "/admin"
|
|
133
|
+
end
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### Step 5: Database Setup (if needed)
|
|
137
|
+
|
|
138
|
+
Ensure your database is set up and migrated:
|
|
139
|
+
|
|
140
|
+
```bash
|
|
141
|
+
# Create database (if not exists)
|
|
142
|
+
rails db:create
|
|
143
|
+
|
|
144
|
+
# Run migrations
|
|
145
|
+
rails db:migrate
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### Step 6: Start Your Rails Server
|
|
149
|
+
|
|
150
|
+
Start your Rails development server:
|
|
151
|
+
|
|
152
|
+
```bash
|
|
153
|
+
rails server
|
|
154
|
+
# or
|
|
155
|
+
rails s
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
### Step 7: Access the Admin Dashboard
|
|
159
|
+
|
|
160
|
+
Open your browser and navigate to:
|
|
161
|
+
|
|
162
|
+
```
|
|
163
|
+
http://localhost:3000/admin
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
You should see the SolidCRUD admin dashboard with all your models listed!
|
|
167
|
+
|
|
168
|
+
## โ
Verification Steps
|
|
169
|
+
|
|
170
|
+
After setup, verify everything works:
|
|
171
|
+
|
|
172
|
+
1. **Dashboard Loads**: Visit `/admin` and see the dashboard
|
|
173
|
+
2. **Models Listed**: Check that all your ActiveRecord models appear
|
|
174
|
+
3. **CRUD Operations**: Click on a model and try:
|
|
175
|
+
- Viewing records (should show paginated list)
|
|
176
|
+
- Creating new records (form should load)
|
|
177
|
+
- Editing existing records (if any exist)
|
|
178
|
+
- Searching and sorting functionality
|
|
179
|
+
|
|
180
|
+
## ๐ง Troubleshooting
|
|
181
|
+
|
|
182
|
+
### Common Issues
|
|
183
|
+
|
|
184
|
+
**Issue: "uninitialized constant Solidcrud"**
|
|
185
|
+
- **Solution**: Make sure `gem 'solidcrud'` is in your Gemfile and you've run `bundle install`
|
|
186
|
+
|
|
187
|
+
**Issue: "No route matches /admin"**
|
|
188
|
+
- **Solution**: Ensure you've added `mount Solidcrud::Engine => "/admin"` to `config/routes.rb`
|
|
189
|
+
|
|
190
|
+
**Issue: "Table doesn't exist" errors**
|
|
191
|
+
- **Solution**: Run `rails db:migrate` to ensure all tables are created
|
|
192
|
+
|
|
193
|
+
**Issue: Models not showing up**
|
|
194
|
+
- **Solution**: Check that your models inherit from `ActiveRecord::Base` and have database tables
|
|
195
|
+
- **Debug**: Add `puts ActiveRecord::Base.descendants.map(&:name)` to see what models Rails finds
|
|
196
|
+
|
|
197
|
+
**Issue: Assets not loading (styling issues)**
|
|
198
|
+
- **Solution**: If using Webpacker, run `rails assets:precompile`
|
|
199
|
+
- **Solution**: If using Propshaft, ensure your asset pipeline is configured correctly
|
|
200
|
+
|
|
201
|
+
**Issue: "undefined method" errors in forms**
|
|
202
|
+
- **Solution**: Ensure your model columns exist in the database schema
|
|
203
|
+
|
|
204
|
+
### Getting Help
|
|
205
|
+
|
|
206
|
+
If you encounter issues:
|
|
207
|
+
|
|
208
|
+
1. Check the Rails server logs for error messages
|
|
209
|
+
2. Verify your Rails and Ruby versions meet requirements
|
|
210
|
+
3. Test with a simple model first (like a basic `Post` or `User` model)
|
|
211
|
+
4. Check the [Issues](https://github.com/solidcrud/solidcrud/issues) page for similar problems
|
|
212
|
+
|
|
213
|
+
### Development Mode Tips
|
|
214
|
+
|
|
215
|
+
For development and testing:
|
|
216
|
+
|
|
217
|
+
```bash
|
|
218
|
+
# Run with verbose logging
|
|
219
|
+
rails s -v
|
|
220
|
+
|
|
221
|
+
# Check what models SolidCRUD detects
|
|
222
|
+
rails c
|
|
223
|
+
> ActiveRecord::Base.descendants.map(&:name)
|
|
224
|
+
> Solidcrud.config.models_exclude
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
## ๐ Requirements
|
|
228
|
+
|
|
229
|
+
- **Ruby**: 2.7+
|
|
230
|
+
- **Rails**: 6.0+ (tested with Rails 6.x, 7.x, and 8.x)
|
|
231
|
+
- **Database**: Any ActiveRecord-supported database
|
|
232
|
+
- **Dependencies**: Automatically handles Bootstrap 5, Font Awesome, and other assets
|
|
233
|
+
|
|
234
|
+
## ๏ฟฝ Authentication & Security
|
|
235
|
+
|
|
236
|
+
SolidCRUD provides flexible authentication options to secure your admin interface. You can now configure authentication types directly at the gem level for cleaner setup.
|
|
237
|
+
|
|
238
|
+
### Quick Authentication Setup
|
|
239
|
+
|
|
240
|
+
Choose your authentication method by configuring it in your SolidCRUD initializer:
|
|
241
|
+
|
|
242
|
+
```ruby
|
|
243
|
+
# config/initializers/solidcrud.rb
|
|
244
|
+
Solidcrud.setup do |config|
|
|
245
|
+
# Choose your authentication type
|
|
246
|
+
config.use_basic_auth # Simple username/password
|
|
247
|
+
# OR
|
|
248
|
+
config.use_devise # Devise integration
|
|
249
|
+
# OR
|
|
250
|
+
config.use_jwt # JWT token authentication
|
|
251
|
+
# OR
|
|
252
|
+
config.use_custom # Custom authentication logic
|
|
253
|
+
|
|
254
|
+
# Configure authentication settings
|
|
255
|
+
config.basic_auth_username = 'admin'
|
|
256
|
+
config.basic_auth_password = 'secure_password'
|
|
257
|
+
config.jwt_secret = 'your-jwt-secret'
|
|
258
|
+
config.devise_scope = :admin_user
|
|
259
|
+
end
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
### Authentication Types
|
|
263
|
+
|
|
264
|
+
#### 1. Basic Authentication (`use_basic_auth`)
|
|
265
|
+
|
|
266
|
+
Simple HTTP basic authentication - perfect for development or small teams:
|
|
267
|
+
|
|
268
|
+
```ruby
|
|
269
|
+
Solidcrud.setup do |config|
|
|
270
|
+
config.use_basic_auth
|
|
271
|
+
config.basic_auth_username = 'admin'
|
|
272
|
+
config.basic_auth_password = 'secure_password_here'
|
|
273
|
+
end
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
**Pros**: Zero dependencies, works everywhere
|
|
277
|
+
**Cons**: Basic auth popup, credentials sent on every request
|
|
278
|
+
|
|
279
|
+
#### 2. Devise Integration (`use_devise`)
|
|
280
|
+
|
|
281
|
+
Automatic integration with Devise authentication:
|
|
282
|
+
|
|
283
|
+
```ruby
|
|
284
|
+
Solidcrud.setup do |config|
|
|
285
|
+
config.use_devise
|
|
286
|
+
config.devise_scope = :admin_user # or :user for regular users
|
|
287
|
+
end
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
**Pros**: Secure, feature-rich, zero configuration
|
|
291
|
+
**Cons**: Requires Devise gem
|
|
292
|
+
|
|
293
|
+
#### 3. JWT Authentication (`use_jwt`)
|
|
294
|
+
|
|
295
|
+
Token-based authentication for APIs and SPAs:
|
|
296
|
+
|
|
297
|
+
```ruby
|
|
298
|
+
Solidcrud.setup do |config|
|
|
299
|
+
config.use_jwt
|
|
300
|
+
config.jwt_secret = ENV['JWT_SECRET']
|
|
301
|
+
end
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
**Pros**: Stateless, scalable, API-friendly
|
|
305
|
+
**Cons**: Requires token management
|
|
306
|
+
|
|
307
|
+
#### 4. Custom Authentication (`use_custom`)
|
|
308
|
+
|
|
309
|
+
Full control over authentication logic:
|
|
310
|
+
|
|
311
|
+
```ruby
|
|
312
|
+
Solidcrud.setup do |config|
|
|
313
|
+
config.use_custom
|
|
314
|
+
|
|
315
|
+
config.authenticate_with do
|
|
316
|
+
# Your custom authentication logic here
|
|
317
|
+
authenticate_user! # Your method
|
|
318
|
+
end
|
|
319
|
+
end
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
**Pros**: Complete flexibility
|
|
323
|
+
**Cons**: Requires implementation
|
|
324
|
+
|
|
325
|
+
### Authentication Methods (Legacy)
|
|
326
|
+
|
|
327
|
+
#### 1. Basic HTTP Authentication (Simplest)
|
|
328
|
+
|
|
329
|
+
Perfect for small teams or development environments:
|
|
330
|
+
|
|
331
|
+
```ruby
|
|
332
|
+
# config/initializers/solidcrud.rb
|
|
333
|
+
Solidcrud.setup do |config|
|
|
334
|
+
config.basic_auth_username = 'admin'
|
|
335
|
+
config.basic_auth_password = 'secure_password_here'
|
|
336
|
+
end
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
**Pros**: Simple setup, no additional dependencies
|
|
340
|
+
**Cons**: Basic auth popup, credentials sent on every request
|
|
341
|
+
|
|
342
|
+
#### 2. Custom Authentication Method (Most Flexible)
|
|
343
|
+
|
|
344
|
+
Integrate with your existing authentication system:
|
|
345
|
+
|
|
346
|
+
```ruby
|
|
347
|
+
# config/initializers/solidcrud.rb
|
|
348
|
+
Solidcrud.setup do |config|
|
|
349
|
+
config.authenticate_with do
|
|
350
|
+
# Check session-based authentication
|
|
351
|
+
if session[:user_id].present?
|
|
352
|
+
return true
|
|
353
|
+
end
|
|
354
|
+
|
|
355
|
+
# Check JWT tokens
|
|
356
|
+
if request.headers['Authorization']&.match?(/^Bearer /)
|
|
357
|
+
token = request.headers['Authorization'].sub(/^Bearer /, '')
|
|
358
|
+
# Verify JWT token and set session
|
|
359
|
+
payload = JWT.decode(token, Rails.application.secret_key_base)[0]
|
|
360
|
+
session[:user_id] = payload['user_id']
|
|
361
|
+
return true
|
|
362
|
+
rescue JWT::DecodeError
|
|
363
|
+
return false
|
|
364
|
+
end
|
|
365
|
+
|
|
366
|
+
# Redirect to your app's login page
|
|
367
|
+
redirect_to '/login', alert: 'Please login to access admin'
|
|
368
|
+
false
|
|
369
|
+
end
|
|
370
|
+
end
|
|
371
|
+
```
|
|
372
|
+
|
|
373
|
+
**Pros**: Full control, integrates with existing auth
|
|
374
|
+
**Cons**: Requires custom implementation
|
|
375
|
+
|
|
376
|
+
#### 3. Automatic Devise Integration
|
|
377
|
+
|
|
378
|
+
If you have Devise installed, SolidCRUD automatically detects and uses it:
|
|
379
|
+
|
|
380
|
+
```ruby
|
|
381
|
+
# No configuration needed! SolidCRUD detects Devise automatically
|
|
382
|
+
# It will call authenticate_user! or authenticate_admin_user!
|
|
383
|
+
```
|
|
384
|
+
|
|
385
|
+
**Pros**: Zero configuration, secure by default
|
|
386
|
+
**Cons**: Requires Devise gem
|
|
387
|
+
|
|
388
|
+
#### 4. Multiple Devise Scopes
|
|
389
|
+
|
|
390
|
+
For applications with different user types:
|
|
391
|
+
|
|
392
|
+
```ruby
|
|
393
|
+
Solidcrud.setup do |config|
|
|
394
|
+
config.authenticate_with do
|
|
395
|
+
if defined?(Devise)
|
|
396
|
+
authenticate_admin_user! # For admin scope
|
|
397
|
+
# or authenticate_user! # For regular users
|
|
398
|
+
end
|
|
399
|
+
true
|
|
400
|
+
end
|
|
401
|
+
end
|
|
402
|
+
```
|
|
403
|
+
|
|
404
|
+
### Security Best Practices
|
|
405
|
+
|
|
406
|
+
#### Production Security
|
|
407
|
+
|
|
408
|
+
1. **Always configure authentication** in production environments
|
|
409
|
+
2. **Use HTTPS** to encrypt all admin traffic
|
|
410
|
+
3. **Exclude sensitive models** from admin interface:
|
|
411
|
+
```ruby
|
|
412
|
+
config.models_exclude = ['User', 'Payment', 'SecretModel']
|
|
413
|
+
```
|
|
414
|
+
4. **Implement authorization** using gems like Pundit or CanCanCan
|
|
415
|
+
5. **Monitor admin access** logs for suspicious activity
|
|
416
|
+
|
|
417
|
+
#### Model Exclusion
|
|
418
|
+
|
|
419
|
+
Always exclude sensitive models in production:
|
|
420
|
+
|
|
421
|
+
```ruby
|
|
422
|
+
# config/initializers/solidcrud.rb
|
|
423
|
+
Solidcrud.setup do |config|
|
|
424
|
+
config.models_exclude = [
|
|
425
|
+
'User', # User authentication data
|
|
426
|
+
'AdminUser', # Admin credentials
|
|
427
|
+
'Payment', # Payment information
|
|
428
|
+
'CreditCard', # Financial data
|
|
429
|
+
'AuditLog', # System logs
|
|
430
|
+
'Session', # Session storage
|
|
431
|
+
'SecretModel' # Any sensitive data
|
|
432
|
+
]
|
|
433
|
+
end
|
|
434
|
+
```
|
|
435
|
+
|
|
436
|
+
### Authentication Examples
|
|
437
|
+
|
|
438
|
+
#### JWT Integration Example
|
|
439
|
+
|
|
440
|
+
```ruby
|
|
441
|
+
config.authenticate_with do
|
|
442
|
+
# Check for JWT in Authorization header
|
|
443
|
+
auth_header = request.headers['Authorization']
|
|
444
|
+
if auth_header&.match?(/^Bearer /)
|
|
445
|
+
token = auth_header.sub(/^Bearer /, '')
|
|
446
|
+
begin
|
|
447
|
+
# Decode and verify JWT
|
|
448
|
+
payload = JWT.decode(token, ENV['JWT_SECRET'])[0]
|
|
449
|
+
|
|
450
|
+
# Check token expiration
|
|
451
|
+
if payload['exp'] < Time.now.to_i
|
|
452
|
+
redirect_to '/login', alert: 'Token expired'
|
|
453
|
+
return false
|
|
454
|
+
end
|
|
455
|
+
|
|
456
|
+
# Check user permissions (admin role required)
|
|
457
|
+
unless payload['role'] == 'admin'
|
|
458
|
+
redirect_to '/unauthorized', alert: 'Admin access required'
|
|
459
|
+
return false
|
|
460
|
+
end
|
|
461
|
+
|
|
462
|
+
# Set user context
|
|
463
|
+
session[:user_id] = payload['user_id']
|
|
464
|
+
session[:user_email] = payload['email']
|
|
465
|
+
|
|
466
|
+
return true
|
|
467
|
+
rescue JWT::DecodeError => e
|
|
468
|
+
Rails.logger.warn "JWT decode error: #{e.message}"
|
|
469
|
+
return false
|
|
470
|
+
end
|
|
471
|
+
end
|
|
472
|
+
|
|
473
|
+
# No valid token found
|
|
474
|
+
redirect_to '/login', alert: 'Authentication required'
|
|
475
|
+
false
|
|
476
|
+
end
|
|
477
|
+
```
|
|
478
|
+
|
|
479
|
+
#### Session-Based Authentication
|
|
480
|
+
|
|
481
|
+
```ruby
|
|
482
|
+
config.authenticate_with do
|
|
483
|
+
# Check if user is logged in via session
|
|
484
|
+
if session[:user_id].present?
|
|
485
|
+
# Optional: Check if user still exists and is admin
|
|
486
|
+
user = User.find_by(id: session[:user_id])
|
|
487
|
+
if user&.admin?
|
|
488
|
+
return true
|
|
489
|
+
else
|
|
490
|
+
# User no longer valid, clear session
|
|
491
|
+
session.delete(:user_id)
|
|
492
|
+
end
|
|
493
|
+
end
|
|
494
|
+
|
|
495
|
+
# Check for "remember me" token
|
|
496
|
+
if cookies.signed[:remember_token].present?
|
|
497
|
+
user = User.find_by(remember_token: cookies.signed[:remember_token])
|
|
498
|
+
if user&.admin?
|
|
499
|
+
session[:user_id] = user.id
|
|
500
|
+
return true
|
|
501
|
+
end
|
|
502
|
+
end
|
|
503
|
+
|
|
504
|
+
# Not authenticated
|
|
505
|
+
redirect_to '/admin/login', alert: 'Please login'
|
|
506
|
+
false
|
|
507
|
+
end
|
|
508
|
+
```
|
|
509
|
+
|
|
510
|
+
#### API Key Authentication
|
|
511
|
+
|
|
512
|
+
```ruby
|
|
513
|
+
config.authenticate_with do
|
|
514
|
+
# Check for API key in header
|
|
515
|
+
api_key = request.headers['X-API-Key'] || params[:api_key]
|
|
516
|
+
|
|
517
|
+
if api_key.present?
|
|
518
|
+
# Validate API key (implement your own validation logic)
|
|
519
|
+
if valid_api_key?(api_key)
|
|
520
|
+
return true
|
|
521
|
+
else
|
|
522
|
+
render json: { error: 'Invalid API key' }, status: :unauthorized
|
|
523
|
+
return false
|
|
524
|
+
end
|
|
525
|
+
end
|
|
526
|
+
|
|
527
|
+
# No API key provided
|
|
528
|
+
render json: { error: 'API key required' }, status: :unauthorized
|
|
529
|
+
false
|
|
530
|
+
end
|
|
531
|
+
```
|
|
532
|
+
|
|
533
|
+
### Testing Authentication
|
|
534
|
+
|
|
535
|
+
#### Testing Basic Auth
|
|
536
|
+
|
|
537
|
+
```bash
|
|
538
|
+
# Test with curl
|
|
539
|
+
curl -u admin:password http://localhost:3000/admin
|
|
540
|
+
|
|
541
|
+
# Test without auth (should fail)
|
|
542
|
+
curl http://localhost:3000/admin
|
|
543
|
+
```
|
|
544
|
+
|
|
545
|
+
#### Testing JWT Auth
|
|
546
|
+
|
|
547
|
+
```bash
|
|
548
|
+
# Test with JWT token
|
|
549
|
+
curl -H "Authorization: Bearer your-jwt-token" http://localhost:3000/admin
|
|
550
|
+
|
|
551
|
+
# Test without token (should redirect)
|
|
552
|
+
curl http://localhost:3000/admin
|
|
553
|
+
```
|
|
554
|
+
|
|
555
|
+
#### Testing in Rails Console
|
|
556
|
+
|
|
557
|
+
```ruby
|
|
558
|
+
# Test authentication configuration
|
|
559
|
+
Solidcrud.config.authenticate_method
|
|
560
|
+
Solidcrud.config.basic_auth_enabled?
|
|
561
|
+
|
|
562
|
+
# Test user authentication methods
|
|
563
|
+
app.get '/admin' # Should redirect if not authenticated
|
|
564
|
+
```
|
|
565
|
+
|
|
566
|
+
### Troubleshooting Authentication
|
|
567
|
+
|
|
568
|
+
#### Common Issues
|
|
569
|
+
|
|
570
|
+
**"Authentication not working"**
|
|
571
|
+
- Check that your `authenticate_with` block returns `true`/`false` correctly
|
|
572
|
+
- Verify session/cookies are working
|
|
573
|
+
- Check Rails logs for authentication-related errors
|
|
574
|
+
|
|
575
|
+
**"Infinite redirect loop"**
|
|
576
|
+
- Ensure your redirect URL is different from the current path
|
|
577
|
+
- Check that authentication check doesn't redirect to itself
|
|
578
|
+
|
|
579
|
+
**"Devise not detected"**
|
|
580
|
+
- Verify Devise gem is installed and required
|
|
581
|
+
- Check that `defined?(Devise)` returns true
|
|
582
|
+
|
|
583
|
+
**"Session not persisting"**
|
|
584
|
+
- Ensure your Rails app has sessions enabled
|
|
585
|
+
- Check session store configuration
|
|
586
|
+
- Verify cookies are being set correctly
|
|
587
|
+
|
|
588
|
+
#### Debug Authentication
|
|
589
|
+
|
|
590
|
+
Add debugging to your authentication block:
|
|
591
|
+
|
|
592
|
+
```ruby
|
|
593
|
+
config.authenticate_with do
|
|
594
|
+
Rails.logger.info "Auth check: session user_id = #{session[:user_id]}"
|
|
595
|
+
Rails.logger.info "Auth check: headers = #{request.headers['Authorization']}"
|
|
596
|
+
|
|
597
|
+
# Your auth logic here...
|
|
598
|
+
|
|
599
|
+
Rails.logger.info "Auth result: #{result}"
|
|
600
|
+
result
|
|
601
|
+
end
|
|
602
|
+
```
|
|
603
|
+
|
|
604
|
+
### Advanced Security
|
|
605
|
+
|
|
606
|
+
#### Rate Limiting
|
|
607
|
+
|
|
608
|
+
Consider adding rate limiting to prevent brute force attacks:
|
|
609
|
+
|
|
610
|
+
```ruby
|
|
611
|
+
# Using rack-attack gem
|
|
612
|
+
Rack::Attack.throttle('admin_login', limit: 5, period: 60) do |req|
|
|
613
|
+
req.ip if req.path == '/admin/login' && req.post?
|
|
614
|
+
end
|
|
615
|
+
```
|
|
616
|
+
|
|
617
|
+
#### Audit Logging
|
|
618
|
+
|
|
619
|
+
Log all admin access for security monitoring:
|
|
620
|
+
|
|
621
|
+
```ruby
|
|
622
|
+
config.authenticate_with do
|
|
623
|
+
# Your auth logic...
|
|
624
|
+
|
|
625
|
+
if authenticated
|
|
626
|
+
Rails.logger.info "Admin access granted: #{current_user.email} from #{request.remote_ip}"
|
|
627
|
+
else
|
|
628
|
+
Rails.logger.warn "Admin access denied from #{request.remote_ip}"
|
|
629
|
+
end
|
|
630
|
+
|
|
631
|
+
authenticated
|
|
632
|
+
end
|
|
633
|
+
```
|
|
634
|
+
|
|
635
|
+
#### Two-Factor Authentication
|
|
636
|
+
|
|
637
|
+
For high-security environments, consider 2FA:
|
|
638
|
+
|
|
639
|
+
```ruby
|
|
640
|
+
config.authenticate_with do
|
|
641
|
+
# Primary authentication (username/password)
|
|
642
|
+
# ... your auth logic ...
|
|
643
|
+
|
|
644
|
+
# Check 2FA if enabled
|
|
645
|
+
if user.two_factor_enabled?
|
|
646
|
+
unless session[:two_factor_verified]
|
|
647
|
+
redirect_to '/admin/2fa', alert: 'Two-factor authentication required'
|
|
648
|
+
return false
|
|
649
|
+
end
|
|
650
|
+
end
|
|
651
|
+
|
|
652
|
+
true
|
|
653
|
+
end
|
|
654
|
+
```
|
|
655
|
+
|
|
656
|
+
### Basic CRUD Operations
|
|
657
|
+
|
|
658
|
+
SolidCRUD automatically provides full CRUD (Create, Read, Update, Delete) operations for all your models:
|
|
659
|
+
|
|
660
|
+
#### Viewing Records
|
|
661
|
+
- **Dashboard**: Visit `/admin` to see all available models
|
|
662
|
+
- **Model List**: Click any model name to see paginated records
|
|
663
|
+
- **Search**: Use the search box to filter records across all text columns
|
|
664
|
+
- **Sort**: Click column headers to sort (ascending/descending)
|
|
665
|
+
- **Pagination**: Navigate through pages (25 records per page)
|
|
666
|
+
|
|
667
|
+
#### Creating Records
|
|
668
|
+
- Click "New [Model]" button
|
|
669
|
+
- Fill out the intelligent form (fields adapt to column types)
|
|
670
|
+
- Click "Create [Model]" to save
|
|
671
|
+
- Validation errors are displayed inline
|
|
672
|
+
|
|
673
|
+
#### Editing Records
|
|
674
|
+
- Click the "Edit" button next to any record
|
|
675
|
+
- Modify fields in the form
|
|
676
|
+
- Click "Update [Model]" to save changes
|
|
677
|
+
- See record creation/update timestamps
|
|
678
|
+
|
|
679
|
+
#### Deleting Records
|
|
680
|
+
- Click the "Delete" button next to any record
|
|
681
|
+
- Confirm deletion in the browser dialog
|
|
682
|
+
- Record is permanently removed
|
|
683
|
+
|
|
684
|
+
### Smart Form Fields
|
|
685
|
+
|
|
686
|
+
SolidCRUD automatically detects the best form field type based on your database columns:
|
|
687
|
+
|
|
688
|
+
#### Automatic Field Detection
|
|
689
|
+
|
|
690
|
+
| Column Type | Form Field | Example |
|
|
691
|
+
|-------------|------------|---------|
|
|
692
|
+
| `boolean` | Checkbox | `active: true` |
|
|
693
|
+
| `date` | Date picker | `birth_date: 1990-01-01` |
|
|
694
|
+
| `datetime`/`timestamp` | Datetime picker | `created_at: 2024-01-01 12:00:00` |
|
|
695
|
+
| `text` | Textarea (4 rows) | Long descriptions |
|
|
696
|
+
| `integer` (foreign key) | Select dropdown | `user_id` โ User dropdown |
|
|
697
|
+
| `decimal`/`float` | Number input | `price: 29.99` |
|
|
698
|
+
|
|
699
|
+
#### Column Name Intelligence
|
|
700
|
+
|
|
701
|
+
| Column Name Pattern | Form Field | Example |
|
|
702
|
+
|-------------------|------------|---------|
|
|
703
|
+
| `email` | Email input with validation | `user_email` |
|
|
704
|
+
| `phone`/`mobile` | Telephone input | `phone_number` |
|
|
705
|
+
| `password` | Password field (hidden) | `password_hash` |
|
|
706
|
+
| `url`/`link`/`website` | URL input with validation | `website_url` |
|
|
707
|
+
| `name`/`title` | Text input | `full_name` |
|
|
708
|
+
| `price`/`amount`/`cost` | Number with currency formatting | `product_price` |
|
|
709
|
+
|
|
710
|
+
### Search Functionality
|
|
711
|
+
|
|
712
|
+
Search works automatically across all text and string columns:
|
|
713
|
+
|
|
714
|
+
```
|
|
715
|
+
Search Examples:
|
|
716
|
+
"john@example.com" โ Finds users with that email
|
|
717
|
+
"Product" โ Finds any record with "Product" in text fields
|
|
718
|
+
"2024" โ Finds dates containing "2024"
|
|
719
|
+
"Active" โ Finds boolean fields or text containing "Active"
|
|
720
|
+
```
|
|
721
|
+
|
|
722
|
+
**Search Behavior:**
|
|
723
|
+
- Searches all `string` and `text` columns
|
|
724
|
+
- Case-insensitive matching
|
|
725
|
+
- Partial matches allowed
|
|
726
|
+
- Maintains sort and pagination state
|
|
727
|
+
|
|
728
|
+
### Sorting and Pagination
|
|
729
|
+
|
|
730
|
+
#### Sorting
|
|
731
|
+
- Click any column header to sort ascending
|
|
732
|
+
- Click again to sort descending
|
|
733
|
+
- Visual indicator shows current sort direction
|
|
734
|
+
- Works with all column types (strings, numbers, dates)
|
|
735
|
+
|
|
736
|
+
#### Pagination
|
|
737
|
+
- Automatically paginates at 25 records per page
|
|
738
|
+
- Shows "X to Y of Z records" counter
|
|
739
|
+
- Previous/Next navigation buttons
|
|
740
|
+
- Direct page number links (for large datasets)
|
|
741
|
+
|
|
742
|
+
### Model Relationships
|
|
743
|
+
|
|
744
|
+
SolidCRUD handles foreign key relationships intelligently:
|
|
745
|
+
|
|
746
|
+
#### Foreign Key Fields
|
|
747
|
+
- Automatically creates dropdown selects
|
|
748
|
+
- Shows related record names (not just IDs)
|
|
749
|
+
- Uses smart display names (name, title, email, etc.)
|
|
750
|
+
- Validates that selected records exist
|
|
751
|
+
|
|
752
|
+
#### Display Names for Relations
|
|
753
|
+
SolidCRUD picks the best display name by checking these attributes in order:
|
|
754
|
+
1. `name`
|
|
755
|
+
2. `title`
|
|
756
|
+
3. `label`
|
|
757
|
+
4. `email`
|
|
758
|
+
5. `username`
|
|
759
|
+
6. Falls back to `"ModelName #ID"`
|
|
760
|
+
|
|
761
|
+
Example: A `Post` belonging to `User` will show the user's name in dropdowns.
|
|
762
|
+
|
|
763
|
+
## โ๏ธ Configuration
|
|
764
|
+
|
|
765
|
+
### Basic Configuration
|
|
766
|
+
|
|
767
|
+
Create `config/initializers/solidcrud.rb` to customize SolidCRUD behavior:
|
|
768
|
+
|
|
769
|
+
```ruby
|
|
770
|
+
# config/initializers/solidcrud.rb
|
|
771
|
+
Solidcrud.setup do |config|
|
|
772
|
+
# Hide sensitive models from the admin interface
|
|
773
|
+
config.models_exclude = ['User', 'AdminUser', 'SecretModel']
|
|
774
|
+
end
|
|
775
|
+
```
|
|
776
|
+
|
|
777
|
+
### Advanced Configuration Examples
|
|
778
|
+
|
|
779
|
+
```ruby
|
|
780
|
+
# config/initializers/solidcrud.rb
|
|
781
|
+
Solidcrud.setup do |config|
|
|
782
|
+
# Exclude multiple model types
|
|
783
|
+
config.models_exclude = [
|
|
784
|
+
'User', # User authentication
|
|
785
|
+
'AdminUser', # Admin users
|
|
786
|
+
'Session', # Session storage
|
|
787
|
+
'Migration', # Migration tracking
|
|
788
|
+
'AuditLog', # Audit trails
|
|
789
|
+
'Payment', # Sensitive payment data
|
|
790
|
+
'SecretModel' # Any other sensitive models
|
|
791
|
+
]
|
|
792
|
+
|
|
793
|
+
# You can also exclude by pattern (future feature)
|
|
794
|
+
# config.exclude_pattern = /.*Secret.*/
|
|
795
|
+
end
|
|
796
|
+
```
|
|
797
|
+
|
|
798
|
+
### Model Discovery Rules
|
|
799
|
+
|
|
800
|
+
SolidCRUD automatically includes models that meet ALL of these criteria:
|
|
801
|
+
|
|
802
|
+
โ
**Included:**
|
|
803
|
+
- Inherits from `ActiveRecord::Base`
|
|
804
|
+
- Is not an abstract class (`abstract_class?` returns false)
|
|
805
|
+
- Has an existing database table (`table_exists?` returns true)
|
|
806
|
+
- Is not in the `models_exclude` list
|
|
807
|
+
|
|
808
|
+
โ **Excluded by default:**
|
|
809
|
+
- Abstract classes (like `ApplicationRecord`)
|
|
810
|
+
- Models without database tables
|
|
811
|
+
- Models listed in `config.models_exclude`
|
|
812
|
+
- Join tables (if following Rails naming conventions)
|
|
813
|
+
|
|
814
|
+
### Configuration File Location
|
|
815
|
+
|
|
816
|
+
The configuration file should be placed at:
|
|
817
|
+
```
|
|
818
|
+
config/initializers/solidcrud.rb
|
|
819
|
+
```
|
|
820
|
+
|
|
821
|
+
This ensures it loads during Rails initialization. The generator creates this file automatically, but you can create it manually if needed.
|
|
822
|
+
|
|
823
|
+
## ๐จ Screenshots
|
|
824
|
+
|
|
825
|
+
### Dashboard Overview
|
|
826
|
+

|
|
827
|
+
|
|
828
|
+
### Model List View
|
|
829
|
+

|
|
830
|
+
|
|
831
|
+
### Create/Edit Forms
|
|
832
|
+

|
|
833
|
+
|
|
834
|
+
### Deployment & Production
|
|
835
|
+
|
|
836
|
+
SolidCRUD is production-ready and includes security considerations:
|
|
837
|
+
|
|
838
|
+
#### Security Best Practices
|
|
839
|
+
|
|
840
|
+
1. **Model Exclusion**: Always exclude sensitive models in production:
|
|
841
|
+
```ruby
|
|
842
|
+
# config/initializers/solidcrud.rb
|
|
843
|
+
Solidcrud.setup do |config|
|
|
844
|
+
config.models_exclude = ['User', 'AdminUser', 'Payment', 'SecretModel']
|
|
845
|
+
end
|
|
846
|
+
```
|
|
847
|
+
|
|
848
|
+
2. **Authentication**: Add authentication to admin routes:
|
|
849
|
+
```ruby
|
|
850
|
+
# config/routes.rb
|
|
851
|
+
authenticate :admin_user do
|
|
852
|
+
mount Solidcrud::Engine => "/admin"
|
|
853
|
+
end
|
|
854
|
+
```
|
|
855
|
+
|
|
856
|
+
3. **Authorization**: Consider adding authorization gems like Pundit or CanCanCan
|
|
857
|
+
|
|
858
|
+
4. **SSL**: Always use HTTPS in production
|
|
859
|
+
|
|
860
|
+
#### Performance Considerations
|
|
861
|
+
|
|
862
|
+
- **Pagination**: Large datasets are automatically paginated
|
|
863
|
+
- **Search**: Efficient database queries with proper indexing
|
|
864
|
+
- **Assets**: Bootstrap and Font Awesome are CDN-loaded by default
|
|
865
|
+
- **Caching**: Consider fragment caching for frequently accessed admin pages
|
|
866
|
+
|
|
867
|
+
#### Monitoring
|
|
868
|
+
|
|
869
|
+
Monitor these areas in production:
|
|
870
|
+
- Admin access logs
|
|
871
|
+
- Database query performance
|
|
872
|
+
- Memory usage during bulk operations
|
|
873
|
+
- Error rates and user feedback
|
|
874
|
+
|
|
875
|
+
### Asset Pipeline Integration
|
|
876
|
+
|
|
877
|
+
SolidCRUD works with all Rails asset pipelines:
|
|
878
|
+
|
|
879
|
+
#### Propshaft (Rails 8 default)
|
|
880
|
+
```ruby
|
|
881
|
+
# config/initializers/assets.rb
|
|
882
|
+
Rails.application.config.assets.precompile += %w( solidcrud/application.css )
|
|
883
|
+
```
|
|
884
|
+
|
|
885
|
+
#### Webpacker/Shakapacker
|
|
886
|
+
Assets are automatically included via the engine.
|
|
887
|
+
|
|
888
|
+
#### Sprockets (Rails < 8)
|
|
889
|
+
```ruby
|
|
890
|
+
# app/assets/stylesheets/application.css
|
|
891
|
+
/*
|
|
892
|
+
*= require solidcrud/application
|
|
893
|
+
*/
|
|
894
|
+
```
|
|
895
|
+
|
|
896
|
+
### Customization Examples
|
|
897
|
+
|
|
898
|
+
#### Custom Styling
|
|
899
|
+
Override SolidCRUD styles in your application:
|
|
900
|
+
|
|
901
|
+
```css
|
|
902
|
+
/* app/assets/stylesheets/admin.css */
|
|
903
|
+
.solidcrud-admin .card {
|
|
904
|
+
border-radius: 8px;
|
|
905
|
+
}
|
|
906
|
+
```
|
|
907
|
+
|
|
908
|
+
#### Custom JavaScript
|
|
909
|
+
Add custom admin JavaScript:
|
|
910
|
+
|
|
911
|
+
```javascript
|
|
912
|
+
// app/assets/javascripts/admin.js
|
|
913
|
+
$(document).on('ready', function() {
|
|
914
|
+
// Custom admin functionality
|
|
915
|
+
});
|
|
916
|
+
```
|
|
917
|
+
|
|
918
|
+
## ๐ ๏ธ Development & Testing
|
|
919
|
+
|
|
920
|
+
### Setting Up Development Environment
|
|
921
|
+
|
|
922
|
+
1. **Clone the repository**:
|
|
923
|
+
```bash
|
|
924
|
+
git clone https://github.com/solidcrud/solidcrud.git
|
|
925
|
+
cd solidcrud
|
|
926
|
+
```
|
|
927
|
+
|
|
928
|
+
2. **Install dependencies**:
|
|
929
|
+
```bash
|
|
930
|
+
bundle install
|
|
931
|
+
```
|
|
932
|
+
|
|
933
|
+
3. **Set up test database**:
|
|
934
|
+
```bash
|
|
935
|
+
cd test/dummy
|
|
936
|
+
bundle install
|
|
937
|
+
rails db:migrate
|
|
938
|
+
cd ../..
|
|
939
|
+
```
|
|
940
|
+
|
|
941
|
+
### Running Tests
|
|
942
|
+
|
|
943
|
+
SolidCRUD uses **Minitest** for comprehensive testing:
|
|
944
|
+
|
|
945
|
+
```bash
|
|
946
|
+
# Run all tests
|
|
947
|
+
bundle exec rake test
|
|
948
|
+
|
|
949
|
+
# Run specific test files
|
|
950
|
+
bundle exec ruby -I test test/lib/solidcrud/version_test.rb
|
|
951
|
+
|
|
952
|
+
# Run with verbose output
|
|
953
|
+
bundle exec rake test -v
|
|
954
|
+
```
|
|
955
|
+
|
|
956
|
+
### Test Structure
|
|
957
|
+
|
|
958
|
+
```
|
|
959
|
+
test/
|
|
960
|
+
โโโ lib/solidcrud/ # Unit tests for core functionality
|
|
961
|
+
โโโ controllers/solidcrud/ # Controller tests
|
|
962
|
+
โโโ integration/ # Integration tests
|
|
963
|
+
โโโ dummy/ # Test Rails application
|
|
964
|
+
โโโ test_helper.rb # Test configuration
|
|
965
|
+
โโโ README.md # Testing documentation
|
|
966
|
+
```
|
|
967
|
+
|
|
968
|
+
### Building & Releasing
|
|
969
|
+
|
|
970
|
+
#### Building the Gem
|
|
971
|
+
```bash
|
|
972
|
+
# Build the gem
|
|
973
|
+
gem build solidcrud.gemspec
|
|
974
|
+
|
|
975
|
+
# Install locally for testing
|
|
976
|
+
gem install solidcrud-0.1.0.gem
|
|
977
|
+
```
|
|
978
|
+
|
|
979
|
+
#### Releasing to RubyGems
|
|
980
|
+
```bash
|
|
981
|
+
# Push to RubyGems (requires account and permissions)
|
|
982
|
+
gem push solidcrud-0.1.0.gem
|
|
983
|
+
```
|
|
984
|
+
|
|
985
|
+
### Code Quality
|
|
986
|
+
|
|
987
|
+
SolidCRUD follows Rails best practices:
|
|
988
|
+
|
|
989
|
+
- **Minitest** for comprehensive testing
|
|
990
|
+
- **Rails 8 compatible** (tested with multiple versions)
|
|
991
|
+
- **Semantic versioning** for releases
|
|
992
|
+
|
|
993
|
+
### Architecture Overview
|
|
994
|
+
|
|
995
|
+
```
|
|
996
|
+
lib/
|
|
997
|
+
โโโ solidcrud.rb # Main module
|
|
998
|
+
โโโ solidcrud/
|
|
999
|
+
โ โโโ engine.rb # Rails engine configuration
|
|
1000
|
+
โ โโโ configuration.rb # User configuration
|
|
1001
|
+
โ โโโ version.rb # Version information
|
|
1002
|
+
โโโ generators/ # Rails generators
|
|
1003
|
+
โโโ tasks/ # Rake tasks (if any)
|
|
1004
|
+
|
|
1005
|
+
test/
|
|
1006
|
+
โโโ lib/solidcrud/ # Unit tests
|
|
1007
|
+
โโโ controllers/solidcrud/ # Controller tests
|
|
1008
|
+
โโโ integration/ # Integration tests
|
|
1009
|
+
โโโ dummy/ # Test Rails application
|
|
1010
|
+
โโโ test_helper.rb # Test configuration
|
|
1011
|
+
|
|
1012
|
+
app/
|
|
1013
|
+
โโโ controllers/ # Admin controllers
|
|
1014
|
+
โโโ helpers/ # View helpers
|
|
1015
|
+
โโโ views/ # Admin interface templates
|
|
1016
|
+
โโโ assets/ # Stylesheets and assets
|
|
1017
|
+
```
|
|
1018
|
+
|
|
1019
|
+
## ๐ Requirements & Compatibility
|
|
1020
|
+
|
|
1021
|
+
### System Requirements
|
|
1022
|
+
|
|
1023
|
+
- **Ruby**: 2.7 or higher
|
|
1024
|
+
- **Rails**: 6.0 or higher
|
|
1025
|
+
- **Database**: Any ActiveRecord-supported database
|
|
1026
|
+
- **Web Server**: Any Rack-compatible server (Puma, Unicorn, etc.)
|
|
1027
|
+
|
|
1028
|
+
### Rails Version Compatibility
|
|
1029
|
+
|
|
1030
|
+
SolidCRUD is tested and compatible with:
|
|
1031
|
+
|
|
1032
|
+
| Rails Version | Status | Notes |
|
|
1033
|
+
|---------------|--------|-------|
|
|
1034
|
+
| Rails 8.x | โ
Fully Supported | Latest features and optimizations |
|
|
1035
|
+
| Rails 7.x | โ
Fully Supported | All features work |
|
|
1036
|
+
| Rails 6.x | โ
Fully Supported | Core functionality maintained |
|
|
1037
|
+
|
|
1038
|
+
### Database Support
|
|
1039
|
+
|
|
1040
|
+
Works with all ActiveRecord-supported databases:
|
|
1041
|
+
|
|
1042
|
+
- **SQLite**: โ
(Default for development)
|
|
1043
|
+
- **PostgreSQL**: โ
(Production recommended)
|
|
1044
|
+
- **MySQL/MariaDB**: โ
|
|
1045
|
+
- **SQL Server**: โ
(Limited testing)
|
|
1046
|
+
- **Oracle**: โ
(Limited testing)
|
|
1047
|
+
|
|
1048
|
+
### Browser Support
|
|
1049
|
+
|
|
1050
|
+
Modern browsers with JavaScript enabled:
|
|
1051
|
+
|
|
1052
|
+
- **Chrome**: 90+
|
|
1053
|
+
- **Firefox**: 88+
|
|
1054
|
+
- **Safari**: 14+
|
|
1055
|
+
- **Edge**: 90+
|
|
1056
|
+
|
|
1057
|
+
### Dependencies
|
|
1058
|
+
|
|
1059
|
+
SolidCRUD automatically includes and manages:
|
|
1060
|
+
|
|
1061
|
+
- **Bootstrap 5**: Responsive UI framework
|
|
1062
|
+
- **Font Awesome**: Icons and visual elements
|
|
1063
|
+
- **Rails UJS**: For form submissions and links
|
|
1064
|
+
- **jQuery** (if configured): For Bootstrap JavaScript components
|
|
1065
|
+
|
|
1066
|
+
No additional frontend dependencies required!
|
|
1067
|
+
|
|
1068
|
+
## ๐ค Contributing
|
|
1069
|
+
|
|
1070
|
+
We welcome contributions! Here's how to get started:
|
|
1071
|
+
|
|
1072
|
+
### Development Setup
|
|
1073
|
+
|
|
1074
|
+
1. **Fork the repository** on GitHub
|
|
1075
|
+
2. **Clone your fork**:
|
|
1076
|
+
```bash
|
|
1077
|
+
git clone https://github.com/your-username/solidcrud.git
|
|
1078
|
+
cd solidcrud
|
|
1079
|
+
```
|
|
1080
|
+
3. **Set up development environment**:
|
|
1081
|
+
```bash
|
|
1082
|
+
bundle install
|
|
1083
|
+
cd test/dummy && bundle install && rails db:migrate && cd ../..
|
|
1084
|
+
```
|
|
1085
|
+
4. **Run tests** to ensure everything works:
|
|
1086
|
+
```bash
|
|
1087
|
+
bundle exec rake test
|
|
1088
|
+
```
|
|
1089
|
+
|
|
1090
|
+
### Making Changes
|
|
1091
|
+
|
|
1092
|
+
1. **Create a feature branch**:
|
|
1093
|
+
```bash
|
|
1094
|
+
git checkout -b feature/your-feature-name
|
|
1095
|
+
# or
|
|
1096
|
+
git checkout -b fix/issue-description
|
|
1097
|
+
```
|
|
1098
|
+
|
|
1099
|
+
2. **Make your changes** following these guidelines:
|
|
1100
|
+
- Add tests for new functionality
|
|
1101
|
+
- Update documentation as needed
|
|
1102
|
+
- Follow Rails naming conventions
|
|
1103
|
+
- Keep the code style consistent
|
|
1104
|
+
|
|
1105
|
+
3. **Run tests** to ensure nothing breaks:
|
|
1106
|
+
```bash
|
|
1107
|
+
bundle exec rake test
|
|
1108
|
+
```
|
|
1109
|
+
|
|
1110
|
+
4. **Update documentation** if needed:
|
|
1111
|
+
- README.md for user-facing changes
|
|
1112
|
+
- Code comments for complex logic
|
|
1113
|
+
- CHANGELOG.md for version updates
|
|
1114
|
+
|
|
1115
|
+
### Pull Request Process
|
|
1116
|
+
|
|
1117
|
+
1. **Commit your changes**:
|
|
1118
|
+
```bash
|
|
1119
|
+
git add .
|
|
1120
|
+
git commit -m "Add feature: brief description of changes"
|
|
1121
|
+
```
|
|
1122
|
+
|
|
1123
|
+
2. **Push to your fork**:
|
|
1124
|
+
```bash
|
|
1125
|
+
git push origin feature/your-feature-name
|
|
1126
|
+
```
|
|
1127
|
+
|
|
1128
|
+
3. **Create a Pull Request** on GitHub:
|
|
1129
|
+
- Use a clear, descriptive title
|
|
1130
|
+
- Provide detailed description of changes
|
|
1131
|
+
- Reference any related issues
|
|
1132
|
+
- Ensure all tests pass
|
|
1133
|
+
|
|
1134
|
+
### Types of Contributions
|
|
1135
|
+
|
|
1136
|
+
**๐ Bug Fixes**
|
|
1137
|
+
- Fix reported issues
|
|
1138
|
+
- Add regression tests
|
|
1139
|
+
- Update documentation
|
|
1140
|
+
|
|
1141
|
+
**โจ New Features**
|
|
1142
|
+
- Implement new functionality
|
|
1143
|
+
- Add comprehensive tests
|
|
1144
|
+
- Update README and examples
|
|
1145
|
+
|
|
1146
|
+
**๐ Documentation**
|
|
1147
|
+
- Improve setup instructions
|
|
1148
|
+
- Add usage examples
|
|
1149
|
+
- Fix typos and clarity issues
|
|
1150
|
+
|
|
1151
|
+
**๐งช Testing**
|
|
1152
|
+
- Add missing test coverage
|
|
1153
|
+
- Improve test reliability
|
|
1154
|
+
- Add integration tests
|
|
1155
|
+
|
|
1156
|
+
### Code Style Guidelines
|
|
1157
|
+
|
|
1158
|
+
- Follow standard Ruby/Rails conventions
|
|
1159
|
+
- Use meaningful variable and method names
|
|
1160
|
+
- Add comments for complex logic
|
|
1161
|
+
- Keep methods focused and single-purpose
|
|
1162
|
+
- Write descriptive test names
|
|
1163
|
+
|
|
1164
|
+
### Testing Requirements
|
|
1165
|
+
|
|
1166
|
+
- All new code must include tests
|
|
1167
|
+
- Tests must pass on all supported Rails versions
|
|
1168
|
+
- Maintain or improve code coverage
|
|
1169
|
+
- Include both unit and integration tests
|
|
1170
|
+
|
|
1171
|
+
### Questions?
|
|
1172
|
+
|
|
1173
|
+
Feel free to open an issue for questions or discussion before starting work on larger features.
|
|
1174
|
+
|
|
1175
|
+
## ๐ Changelog
|
|
1176
|
+
|
|
1177
|
+
See [CHANGELOG.md](CHANGELOG.md) for version history and changes.
|
|
1178
|
+
|
|
1179
|
+
## ๐ Bug Reports & Support
|
|
1180
|
+
|
|
1181
|
+
### Reporting Bugs
|
|
1182
|
+
|
|
1183
|
+
Found a bug? Please [open an issue](https://github.com/solidcrud/solidcrud/issues) with detailed information:
|
|
1184
|
+
|
|
1185
|
+
**Required Information:**
|
|
1186
|
+
- **Rails version**: `rails --version`
|
|
1187
|
+
- **Ruby version**: `ruby --version`
|
|
1188
|
+
- **SolidCRUD version**: `gem list solidcrud`
|
|
1189
|
+
- **Database**: PostgreSQL/MySQL/SQLite version
|
|
1190
|
+
- **Browser**: Chrome/Firefox/Safari version (for UI issues)
|
|
1191
|
+
|
|
1192
|
+
**Bug Report Template:**
|
|
1193
|
+
```markdown
|
|
1194
|
+
## Bug Description
|
|
1195
|
+
Brief description of the issue
|
|
1196
|
+
|
|
1197
|
+
## Steps to Reproduce
|
|
1198
|
+
1. Step 1
|
|
1199
|
+
2. Step 2
|
|
1200
|
+
3. Step 3
|
|
1201
|
+
|
|
1202
|
+
## Expected Behavior
|
|
1203
|
+
What should happen
|
|
1204
|
+
|
|
1205
|
+
## Actual Behavior
|
|
1206
|
+
What actually happens
|
|
1207
|
+
|
|
1208
|
+
## Environment
|
|
1209
|
+
- Rails: X.X.X
|
|
1210
|
+
- Ruby: X.X.X
|
|
1211
|
+
- SolidCRUD: X.X.X
|
|
1212
|
+
- Database: XXX
|
|
1213
|
+
- Browser: XXX
|
|
1214
|
+
|
|
1215
|
+
## Additional Context
|
|
1216
|
+
Any other relevant information, logs, or screenshots
|
|
1217
|
+
```
|
|
1218
|
+
|
|
1219
|
+
### Common Issues & Solutions
|
|
1220
|
+
|
|
1221
|
+
**"Model not showing in admin"**
|
|
1222
|
+
- Check if model inherits from `ActiveRecord::Base`
|
|
1223
|
+
- Verify table exists: `rails db:migrate`
|
|
1224
|
+
- Check if model is excluded in configuration
|
|
1225
|
+
|
|
1226
|
+
**"Form field not working correctly"**
|
|
1227
|
+
- Verify column exists in database schema
|
|
1228
|
+
- Check column type matches expected behavior
|
|
1229
|
+
- Look for validation errors in Rails logs
|
|
1230
|
+
|
|
1231
|
+
**"Assets not loading"**
|
|
1232
|
+
- Run `rails assets:precompile` if using asset pipeline
|
|
1233
|
+
- Check browser console for CSS/JS errors
|
|
1234
|
+
- Verify Bootstrap/Font Awesome are loading
|
|
1235
|
+
|
|
1236
|
+
### Getting Help
|
|
1237
|
+
|
|
1238
|
+
- **Documentation**: Check this README and inline code comments
|
|
1239
|
+
- **Issues**: Search existing [GitHub issues](https://github.com/solidcrud/solidcrud/issues)
|
|
1240
|
+
- **Discussions**: Use [GitHub Discussions](https://github.com/solidcrud/solidcrud/discussions) for questions
|
|
1241
|
+
|
|
1242
|
+
## ๐ก Feature Requests
|
|
1243
|
+
|
|
1244
|
+
Have ideas for SolidCRUD? We'd love to hear them!
|
|
1245
|
+
|
|
1246
|
+
### Requesting Features
|
|
1247
|
+
|
|
1248
|
+
[Open an issue](https://github.com/solidcrud/solidcrud/issues) with the "enhancement" label and include:
|
|
1249
|
+
|
|
1250
|
+
- **Feature Description**: What should the feature do?
|
|
1251
|
+
- **Use Case**: Why is this feature needed?
|
|
1252
|
+
- **Implementation Ideas**: How could this be implemented?
|
|
1253
|
+
- **Mockups/Screenshots**: Visual examples if applicable
|
|
1254
|
+
|
|
1255
|
+
### Feature Priorities
|
|
1256
|
+
|
|
1257
|
+
We're particularly interested in:
|
|
1258
|
+
- **UI/UX Improvements**: Better responsive design, accessibility
|
|
1259
|
+
- **Performance**: Faster loading, better pagination
|
|
1260
|
+
- **New Field Types**: Support for more database column types
|
|
1261
|
+
- **Customization**: More configuration options
|
|
1262
|
+
- **Integrations**: Better support for popular gems
|
|
1263
|
+
|
|
1264
|
+
### Contributing Features
|
|
1265
|
+
|
|
1266
|
+
For larger features, consider:
|
|
1267
|
+
1. Opening an issue to discuss the feature first
|
|
1268
|
+
2. Breaking down into smaller, manageable PRs
|
|
1269
|
+
3. Including comprehensive tests
|
|
1270
|
+
4. Updating documentation
|
|
1271
|
+
|
|
1272
|
+
## ๐ License
|
|
1273
|
+
|
|
1274
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
1275
|
+
|
|
1276
|
+
## ๐ Acknowledgments
|
|
1277
|
+
|
|
1278
|
+
- Built with โค๏ธ for the Rails community
|
|
1279
|
+
- Inspired by Django Admin and Rails Admin gems
|
|
1280
|
+
- Bootstrap 5 for the beautiful UI
|
|
1281
|
+
- Font Awesome for the icons
|
|
1282
|
+
|
|
1283
|
+
---
|
|
1284
|
+
|
|
1285
|
+
**โญ If SolidCRUD helps you, please star the repository! It helps others discover the project.**
|