Namaskar developers! π Agar aap modern, responsive websites banana chahte hain aur Tailwind CSS ko apne Rails project mein integrate karna chahte hain, toh yeh guide aapke liye hai. Chaliye step-by-step seekhte hain:
1. Pehli Setting: Tailwind Setup Karo
Terminal mein yeh commands chalao:
# Rails project create karo (agar nahi hai toh)
rails new my_app -d postgresql
# Tailwind CSS ke liye official gem add karo
bundle add tailwindcss-rails
# Tailwind install karo
rails tailwindcss:install
β Kya Hua?
tailwindcss-rails
gem add huiapp/assets/stylesheets/application.tailwind.css
file banibin/dev
script update hui (foreman ke saath)
2. Important Files ko Samjho
application.tailwind.css (Tailwind ka entry point)
@tailwind base;
@tailwind components;
@tailwind utilities;
Procfile.dev (Automatic compilation ke liye)
web: bin/rails server -p 3000
css: bin/rails tailwindcss:watch
3. Views mein Tailwind Use Karo
Kisi bhi view file (e.g., app/views/home/index.html.erb
) mein try karo:
<div class="bg-blue-500 text-white p-8 text-center">
<h1 class="text-4xl font-bold">Swagat Hai!</h1>
<p class="mt-4">Yeh Tailwind CSS ka magic hai π₯</p>
<button class="mt-6 bg-yellow-400 hover:bg-yellow-500 px-6 py-2 rounded-full">
Click Karo
</button>
</div>
4. Server Start Karo
Tailwind ko automatic compile karne ke liye new command use karo:
bin/dev # Regular 'rails s' se Tailwind compile nahi hoga!
Ab localhost:3000
visit karo – dekho Tailwind ka chamatkar! β¨
5. Customization (Theme Badlo)
config/tailwind.config.js
file edit karke apna style define karo:
module.exports = {
theme: {
extend: {
colors: {
'mera-custom-color': '#ff00ff',
}
}
}
}
CSS mein use karo:
<div class="bg-mera-custom-color">Mast rang!</div>
6. Production Build Taiyar Karo
Deploy se pehle CSS optimize karo:
rails tailwindcss:build
7. Common Problems & Solutions
Problem 1: Styles kaam nahi kar rahe
- Solution:
bin/dev
se server start karo (regularrails s
nahi) - Check karo
application.html.erb
mein yeh line hai:
<%= stylesheet_link_tag "application", "data-turbo-track": "reload" %>
Problem 2: Custom classes add karni hain
- Solution:
@layer
use karoapplication.tailwind.css
mein:
@layer components {
.mera-btn {
@apply px-4 py-2 bg-red-500 rounded-lg;
}
}
Problem 3: PurgeCSS ko content dikhao
tailwind.config.js
mein yeh ensure karo:
content: [
'./app/views/**/*.html.erb',
'./app/helpers/**/*.rb',
'./app/assets/stylesheets/**/*.css',
'./app/javascript/**/*.js'
],
8. Pro Tips β¨
- Dev Tools: Browser DevTools mein Tailwind classes edit kar direct dekho changes
- Plugins:
yarn add @tailwindcss/forms @tailwindcss/typography
tailwind.config.js
mein add karo:
plugins: [require('@tailwindcss/forms'), require('@tailwindcss/typography')]
- VSCode Extension: “Tailwind CSS IntelliSense” install karo for autocomplete
Final Structure
my_app/
βββ app/
β βββ assets/
β βββ stylesheets/
β βββ application.tailwind.css # Yeh hai hamari Tailwind entry
βββ config/
β βββ tailwind.config.js # Customizations yahan
βββ Procfile.dev # Foreman config
Aakhri Baat:
Tailwind CSS = “Utility-first” magic jo development speed rocket bana deta hai! π
“Pehle Bootstrap ka istemal karte the, ab Tailwind ki mohabbat ho gayi hai!” π
Happy Coding! π
“bin/dev
chalao, chai piyo, aur awesome UIs banao!” βοΈπ»