Frontend
Server HTML render करता है; Turbo उसे SPA जैसा अनुभव देता है; Stimulus छोटे-छोटे behaviors जोड़ता है; daisyUI components देता है। Replay pages की तुलना visible text से करता है, इसलिए हर content और हर flow बनाए रखें; markup आपकी मर्ज़ी का है।
Setup (ज़्यादातर काम front-door कर देता है)
app/assets/tailwind/application.css:css@import "tailwindcss"; @plugin "./daisyui.mjs" { themes: light --default, dark --prefersdark; }daisyui.mjsऔरdaisyui-theme.mjsइसके बगल में रहते हैं (daisyUI releases से download किए गए; Tailwind का standalone CLI इन्हें बिना Node के load करता है)। Views edit करते समयbin/dev(याbin/rails tailwindcss:watch) चलाएँ।- Theme: layout में
<html data-theme="light">; theme switcher एक Stimulus controller है जोdocument.documentElement.dataset.themeset करता है और उसे cookie में store करता है। - Layout: original के links के साथ daisyUI
navbar(या side navigation के लिएdrawer),container mx-auto p-4के साथmain, flash messagesalert alert-success/alert-errorके रूप में।
Mapping
| Original | Rails |
|---|---|
| Page / route component (React, Vue, Angular, Svelte, Next.js page) | Controller action + app/views/<resource>/<action>.html.erb |
दोबारा इस्तेमाल होने वाला component (<ProductCard>) |
Partial _product_card.html.erb (या logic के साथ दोहराए जाने पर ViewComponent) |
| Props | Partial locals: render "product_card", product: p |
Client router links (<Link>, router.push) |
link_to / button_to; SPA navigation Turbo Drive करता है |
सिर्फ़ UI state के लिए useState / ref (open, tab, toggle) |
static values और targets वाला Stimulus controller |
Fetch करके render (useEffect(fetch), SWR, React Query) |
Server पर render करें; lazy हिस्से <turbo-frame src=... loading="lazy"> में |
| Client-side submit + JSON API वाला form | form_with model:; errors status: :unprocessable_entity के साथ फिर से render होते हैं |
| Optimistic update / live list | Turbo Stream response (turbo_stream.append/replace/remove) |
| WebSocket / polling updates | turbo_stream_from @room + model पर broadcasts_to (Action Cable) |
| Modal | Stimulus controller से खुलने वाला daisyUI modal (<dialog>), content turbo-frame id="modal" में |
| Infinite scroll / "load more" | अगले page के लिए loading="lazy" वाला Turbo Frame |
| Debounced search-as-you-type | Stimulus controller जो 300 ms बाद form submit करता है; results Turbo Frame में |
| Client-side validation (zod, yup) | ActiveModel validations, HTML5 required/pattern; daisyUI validator class |
| CSS modules / styled-components / Bootstrap classes | Tailwind utilities + daisyUI components |
| Global store (Redux, Pinia, Context) | Server ही store है; हर user की state के लिए session; cross-controller UI के लिए Stimulus outlets |
| i18n strings | config/locales/*.yml + t(".key") |
| Server templates (Jinja, Thymeleaf, Blade, EJS, Razor, Go templates) | ERB: {{ x }} -> <%= x %>, {% for %} -> <% each do %>, blocks/sections -> content_for / yield, includes -> partials |
किन daisyUI components का इस्तेमाल करें
btn (btn-primary, btn-ghost, btn-sm), card (card-body, card-title, card-actions),
navbar, menu, drawer, table (table-zebra), badge, alert, modal, tabs, dropdown,
fieldset + label के साथ input/select/textarea (daisyUI 5), grouped buttons और
pagination के लिए join, dashboards के लिए stat, wizards के लिए steps, flash के लिए toast, lazy frames के लिए skeleton और
loading।
Rules
- Original जैसे ही URLs, वही page titles (
content_for :title), वही headings, labels, button text, table columns और empty states: replay text जाँचता है। - Forms उन्हीं paths पर उन्हीं field names के साथ post करते हैं, जब तक कोई ADR कुछ और न कहे;
nameattributes रखें ताकि recorded POST cases चलते रहें। - Original ने पहली load पर जो कुछ दिखाया, वह सब server-render करें; सिर्फ़ वही चीज़ें lazy frames बनती हैं जो original में lazy थीं।
- Accessibility: असली
<button>/<a>,<label for>, Turbo Stream targets परaria-live, modals में focus ले जाएँ। सही element इस्तेमाल करने पर daisyUI components accessible होते हैं। - कोई inline
<script>नहीं। Behaviorapp/javascript/controllers/*_controller.jsमें जाता है (bin/rails generate stimulus name), importmap से pinned। - जिस भी flow में JavaScript behavior है, उसके लिए system tests (
bin/rails generate system_test)।