Skip to content

Instantly share code, notes, and snippets.

@bensheldon
Last active April 4, 2025 20:02
Show Gist options
  • Save bensheldon/00c23699bfb1857acbc2e9225de8adb1 to your computer and use it in GitHub Desktop.
Save bensheldon/00c23699bfb1857acbc2e9225de8adb1 to your computer and use it in GitHub Desktop.

My theory is that folks are hallucinating complex structure for these docs. If you read the Cursor forums, people are asking the Cursor LLM how to format them 🙃 Those shared above are the results of writing in the UI and what gets puts into version control.

My approach is that when I am annoyed by something I have to manually fix up, I go update the file.

Some of it is just impossible, like using the new Strong Params expects syntax given the training cutoffs. I’m not going to completely document the interface (cursor/rules can’t link to docs and can only link to a single file) . So I hint it, and it simply hallucinates the interface mostly correctly most of the time. Principle of Least Surprise in practice!

My .cursorrules were pretty inconsistent project to project, and I don’t believe that putting very generic things like “Use exceptions for exceptional cases, not for control flow” or “Use Active Record effectively” improves things.

---
description: Changes to Rails Controllers
globs: app/controllers/*
alwaysApply: false
---
# When modifying Rails controllers
## Routes
When adding new controllers or actions, don't forget to update the [routes.rb](mdc:config/routes.rb)
## Strong Params
Use `expect` syntax instead of `require`/`allow`
```
# Bad
params.require(:user).permit(:name, :favorite_pie)
# Good
params.expect(user: [:name, :favorite_pie])
```
## Wizard flows
Controllers in the `Apply` namespace are part of a form wizard. Each controller represents a stage in the from wizard flow. The flow is implemented in [flowable.rb](mdc:app/controllers/concerns/flowable.rb) and the stages are declared in [base_controller.rb](mdc:app/controllers/apply/base_controller.rb). To redirect to the next stage of the flow, use `flow_next_path`.
## Same-controller paths and redirects
When linking or redirecting to an action in the same controller, always use `url_for(action: "the_action")` with implicit controller instead of a path helper:
```
# Bad
my_controller_the_action_path
# Good
url_for(action: "the_action")
```
---
description: Rules for migrations
globs: db/*
alwaysApply: false
---
# Database migration rules
- The database is Postgres
- Use `text` for all string fields; never use `string` or `varchar`
- Use `datetime` instead of `timestamp`
- Assume that Boolean values should be nullable unless specified
---
description: RSpec testing rules
globs: spec/*
alwaysApply: false
---
# Rules for writing RSpec tests
- Write comprehensive tests using RSpec. It's ok to put multiple assertions in the same example.
- Use factories (FactoryBot) for test data generation.
- When writing System Tests. Use `css_id(*)` and `css_class(*)` instead of `"#{dom_id(*)}"` `"#{dom_class(*)}"`
- `shoulda-matchers` is not installed. Don't test declarative configuration. For validations, only test that it's not valid when the validation is violated.
- `rails-controller-testing` is not installed. Test controllers behaviorally: correct status code and/or model changes. Don't use `assigns` to inspect ivars.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment