From 0ba6634e99b3d80a2f93dbd15c95c5c9801b5570 Mon Sep 17 00:00:00 2001 From: kbe Date: Tue, 2 Sep 2025 22:43:14 +0200 Subject: [PATCH] fix: Correct ticket creation flow and home page availability check MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Fix incorrect route helper in tickets controller (order_checkout_path -> checkout_order_path) - Add missing set_event before_action for create action - Fix home page availability check to use ticket_types.available_quantity instead of tickets.quantity - Update AGENT.md with ast-grep documentation for development tools 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- AGENT.md | 33 +++++++++++++++++++++++++++ app/controllers/tickets_controller.rb | 4 ++-- app/views/pages/home.html.erb | 2 +- 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/AGENT.md b/AGENT.md index de9e238..6a2fdb1 100755 --- a/AGENT.md +++ b/AGENT.md @@ -256,6 +256,38 @@ events = Event.create!([...]) ticket_types = TicketType.create!([...]) ``` +## 🛠️ Available Development Tools + +### AST-Grep for Mass Code Replacement + +The system has `ast-grep` installed for structural code search and replacement. This tool is particularly useful for: + +- **Mass refactoring**: Rename methods, classes, or variables across the codebase +- **Pattern-based replacements**: Update code patterns using AST matching +- **Language-aware transformations**: Safer than regex for code modifications + +#### Usage Examples: + +```bash +# Find all method calls to a specific method +ast-grep --pattern 'find_by_$FIELD($VALUE)' --lang ruby + +# Replace method calls with new syntax +ast-grep --pattern 'find_by_$FIELD($VALUE)' --rewrite 'find_by($FIELD: $VALUE)' --lang ruby + +# Search for specific Rails patterns +ast-grep --pattern 'validates :$FIELD, presence: true' --lang ruby + +# Mass rename across multiple files +ast-grep --pattern 'old_method_name($$$ARGS)' --rewrite 'new_method_name($$$ARGS)' --lang ruby --update-all +``` + +#### Best Practices: +- Always run with `--dry-run` first to preview changes +- Use `--lang ruby` for Ruby files to ensure proper AST parsing +- Test changes in a branch before applying to main codebase +- Particularly useful for Rails conventions and ActiveRecord pattern updates + ## 📝 Code Style & Conventions - **Ruby Style**: Follow Rails conventions and Rubocop rules @@ -263,5 +295,6 @@ ticket_types = TicketType.create!([...]) - **JavaScript**: Stimulus controllers for interactive behavior - **CSS**: Tailwind utility classes with custom components - **Documentation**: Inline comments for complex business logic +- **Mass Changes**: Use `ast-grep` for structural code replacements instead of simple find/replace This architecture provides a solid foundation for a scalable ticket selling platform with proper separation of concerns, security, and user experience. \ No newline at end of file diff --git a/app/controllers/tickets_controller.rb b/app/controllers/tickets_controller.rb index 2deee6a..2ccd1e9 100644 --- a/app/controllers/tickets_controller.rb +++ b/app/controllers/tickets_controller.rb @@ -4,7 +4,7 @@ # complete their details and proceed to payment class TicketsController < ApplicationController before_action :authenticate_user!, only: [ :new, :payment_success, :payment_cancel ] - before_action :set_event, only: [ :new ] + before_action :set_event, only: [ :new, :create ] # Handle new ticket creation # @@ -87,7 +87,7 @@ class TicketsController < ApplicationController if success session[:draft_order_id] = @order.id session.delete(:pending_cart) - redirect_to order_checkout_path(@order) + redirect_to checkout_order_path(@order) else redirect_to ticket_new_path(@event.slug, @event.id) end diff --git a/app/views/pages/home.html.erb b/app/views/pages/home.html.erb index f35fb72..9f6979a 100755 --- a/app/views/pages/home.html.erb +++ b/app/views/pages/home.html.erb @@ -36,7 +36,7 @@ <% if event.featured? %> ★ En vedette <% end %> - <% if event.tickets.any? { |ticket| ticket.quantity > 0 } %> + <% if event.ticket_types.any? { |ticket_type| ticket_type.available_quantity > 0 } %> Disponible <% end %>