你用 Rails 的方式不对。
Doing Rails Wrong

原始链接: https://www.bananacurvingmachine.com/articles/you-re-doing-rails-wrong

这段对话突显了在Rails 8应用中尝试集成较新工具时,现代Web开发日益增长的复杂性。凯文热情地提倡一种混合技术栈——Vite、React、TypeScript以及Babel、PostCSS、Tailwind、ESLint、Prettier和Husky等一系列相关工具,以实现“极快的”性能。 然而,这需要大量的设置,包括Node.js、Docker、Redis,以及针对特定功能可能需要的Next.js/Remix或StimulusReflex/ActionCable。约翰最初感到好奇,但很快就被所需的大量依赖和配置所淹没。 讽刺的是,凯文将这种复杂性称为“简单”,而约翰展示了一个完全可用的、速度极快的Rails应用,它*仅*使用Rails构建,表明核心框架在没有额外开销的情况下仍然非常高效。这次交流最终强调了一种对追逐流行技术,以牺牲简单性和强大、优化的基础框架的批判。

一篇名为“你对Rails理解错了”的文章引发了Hacker News的讨论,凸显了Web开发中一个持续存在的争论。核心观点围绕着Ruby on Rails的优势——开箱即用和简洁性——与JavaScript生态系统经常出现的复杂性和碎片化之间的对比。 许多评论者表达了对JavaScript的“工具疲劳”,并欣赏Rails的效率。一些人预测,随着编码代理的兴起,Rails可能会迎来“复兴”,因为编码代理难以处理过度的复杂性。然而,也有人指出Rails在新生产环境中的地位正在下降,经常被静态构建和JavaScript框架所取代。 一个关键点是,用户通常无法察觉Rails或React应用程序之间的区别,而简洁性可能是一种优势。讨论质疑了对于更简单的应用程序来说,过度工程化的前端堆栈的必要性,并提到了像37signals这样的公司,它们仍然有效地使用Rails。
相关文章

原文

Kevin: Hey, have you tried Vite for Rails 8? It’s insanely fast.

John: I’ve heard of it. Isn’t that a build tool? Didn’t Rails already come with one?

K: Well, it did, but Vite is like… modern. You’ll need to install Node, npm, and configure a few scripts, but it’s totally worth it.

J: Wait, Rails needs Node now?

K: Well, yeah — if you want to use React. Everyone’s using React.

J: Didn’t Rails have something for that?

K: It did, but now you’ll want to use Vite with React Refresh so you get instant component reloads. And if you want TypeScript support, you’ll have to configure that too.

J: Sounds… like a lot.

K: Oh, not really. Just install Babel, configure your .babelrc, add vite-plugin-ruby, then you’ll want PostCSS for your styles.

J: PostCSS?

K: Yeah, and then Tailwind, obviously — you don’t want to write CSS like a peasant.

J: Of course not.

K: Then you’ll probably want to add ESLint and Prettier to make sure your code looks clean, and maybe Husky for pre-commit hooks.

J: So... Vite, React, Babel, PostCSS, Tailwind, ESLint, Prettier, Husky. That’s it?

K: Pretty much. Oh, unless you want server-side rendering — then you’ll need Next.js or Remix.

J: Wait, we’re still talking about a Rails app, right?

K: Yeah, but hybrid stacks are the way to go! You could also use StimulusReflex or Hotwire if you want reactive components without JS frameworks.

J: StimulusReflex sounds like a Marvel character.

K: Ha! No, it’s for real-time updates. But you’ll need ActionCable configured, Redis running, and—

J: Redis?

K: Yeah, you need a pub/sub layer. Don’t worry, it’s just another Docker container.

J: Docker too?

K: Yeah, to isolate your dependencies. And if you want everything reproducible, you’ll need Docker Compose, maybe Fly.io for deployment, and a build pipeline with GitHub Actions.

J: That’s... quite a setup.

K: It’s just modern web development, man. Keeps things simple. What are you doing?

J: Just tinkering.

(John runs a single command. The app boots instantly, working forms, instant loading times, blazing fast navigation.)

K: Wow, that looks like a pretty complex setup. What stack’s that?

J: Vanilla Rails.

Just F#$%^& use Rails.

联系我们 contact @ memedata.com