Created
June 2, 2025 08:50
-
-
Save forsbergplustwo/2ce893ddade3fcd7ec26376182c64943 to your computer and use it in GitHub Desktop.
Cursor Prompt Templates
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
p-refactor-c | |
Refactor this Rails 7 controller to | |
Additional instructions: | |
- We want slim controllers with logic in model, PORO, or concern. | |
- Only use RESTful routes. Use namespaces/nested resources for additional actions. | |
- Check context in the following directories and files: | |
app/controllers/ | |
app/models/ | |
app/views/ | |
test/controllers/ | |
config/routes.rb | |
Gemfile | |
- Ensure correct use of private methods. | |
- Ensure params sanitization. | |
- Ensure tests exist and are up to date | |
P-refactor-m | |
Refactor this Rails 7 model to | |
Additional instructions: | |
- We want to clean up fat models, isolate logic and reduce callbacks. Prefer descriptive class, method and variable names over short or abbreviated names. | |
- Extract complex logic into nested PORO classes. | |
Example: Template::Duplicator | |
- Prefer enum like state changes for complex logic (PORO), on the parent class. | |
Example: def create_duplicate!(name: ) Template::Duplicator.new(name: template: self).create! | |
end | |
- Ensure correct use of associations, scopes, callbacks and private methods. | |
- Ensure MiniTest Unit tests exist and are up to date for public methods. Do not create tests for built in rails features such as associations, callbacks etc. | |
- Stick to vanilla rails conventions, do not use Service Objects, Presenters or any other non-standard patterns. | |
P-refactor-js | |
Refactor this Hotwire Stimulus controller for clarity and structure. | |
Additional instructions: | |
- We want to clean up fat models, isolate logic and reduce callbacks. Prefer descriptive class, method and variable names over short or abbreviated names. | |
- Extract complex logic into private methods. | |
- Structure should be in the following order and headings: // Static properties | |
// params comment describing which are used (if used) | |
// Lifecycle methods | |
// Actions | |
// Event Listeners & messages | |
// Private | |
- Do not add additional comments, structure, headings or methods that are not implemented in this specific controller (no placeholders) | |
- Ensure correct use of Stimulus static properties (with defaults), targets, values, params and connected callbacks. | |
- Stick to vanilla javascript and Hotwire Stimulus conventions. | |
- Never change the underlying behaviour. - Example structure: | |
import { Controller } from "@hotwired/stimulus"; | |
/** | |
* Controls the behavior of a remote modal dialog | |
* Handles modal creation, messaging, and cleanup | |
*/ | |
export default class extends Controller { | |
// Static properties | |
static targets = ["modal", "submitButton"]; | |
// Params used: | |
// - url: The URL of the modal content | |
// - title: The title displayed in the modal header | |
// - submitButtonText: Text for the submit button (optional) | |
// - submitButtonDisabledOnLoad: Whether submit is initially disabled (optional) | |
// Lifecycle methods | |
connect() { | |
this.handleInitialTrigger(); | |
} | |
// Actions | |
// Event Listeners & messages | |
// Private | |
P-tests-m | |
Add Rails 7 MiniTests for this code | |
Additional instructions: | |
- Test only public methods | |
- Test outcomes and not implementation details | |
- Use fixtures for model related data. Add fixtures if necessary. | |
- Use Mocha for mocks/stubs (only if necessary, prefer fixture data) | |
- Check the following files for context before planning or implementing the tests: | |
app/models/ | |
app/controllers/ | |
tests/ | |
Gemfile | |
- Do not test rails built in features like associations, or built in validators. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment