CRUD App

Demonstrating Stimulus Action Parameters with Ruby (Opal) + Vite

Features Demonstrated:

  • action_param(:name) - Get action parameter
  • action_param_int(:id) - Get integer parameter
  • has_action_param?(:name) - Check if parameter exists
  • data-[controller]-[name]-param - HTML attribute syntax

Items

No items yet. Add one above!
0
Total Items
0
Total Quantity

How Action Parameters Work

HTML Syntax:

<button data-action="list#edit"
        data-list-id-param="123"
        data-list-name-param="Item Name">
  Edit
</button>

Ruby Controller Code:

def edit
  # Get parameters using StimulusHelpers
  id = action_param_int(:id)
  name = action_param(:name)

  # Check if parameter exists
  if has_action_param?(:quantity)
    quantity = action_param_int(:quantity)
  end

  # Use the parameters
  puts "Editing item #{id}: #{name}"
end