Hacker News 中文摘要

RSS订阅

你的Rails用错了 -- You're Doing Rails Wrong

文章摘要

文章讨论在Rails 8中使用Vite等现代前端工具的必要性,涉及React、TypeScript、Babel、PostCSS、Tailwind等配置,反映了现代Web开发中前后端技术栈融合的趋势和复杂性。对话展现了传统Rails开发者对新工具链的困惑与适应过程。

文章总结

标题:香蕉弯曲机

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

对话内容: 凯文:嘿,你试过在Rails 8里用Vite吗?速度快得离谱。

约翰:听说过。那不是个构建工具吗?Rails不是自带了一个?

凯文:是自带,但Vite更...现代化。你得装Node、npm,再配几个脚本,但绝对值得。

约翰:等等,Rails现在需要Node了?

凯文:对啊——如果你想用React的话。现在大家都在用React。

约翰:Rails不是有自己的方案吗?

凯文:有是有,但现在你得用Vite配合React Refresh实现组件即时重载。要支持TypeScript还得另外配置。

约翰:听起来...挺复杂。

凯文:其实还好。装个Babel,配好.babelrc,加个vite-plugin-ruby,再用PostCSS处理样式。

约翰:PostCSS?

凯文:对,当然还得用Tailwind——总不能用原始CSS吧。

约翰:那当然。

凯文:接着最好装ESLint和Prettier保持代码整洁,可能还要Husky做提交前检查。

约翰:所以...Vite、React、Babel、PostCSS、Tailwind、ESLint、Prettier、Husky。就这些?

凯文:差不多。哦,除非你要服务端渲染——那就得用Next.js或Remix。

约翰:我们说的还是Rails应用吧?

凯文:是啊,但混合技术栈才是趋势!如果不想用JS框架,也可以用StimulusReflex或Hotwire做响应式组件。

约翰:StimulusReflex听着像漫威角色。

凯文:哈!这是用来做实时更新的。不过得配ActionCable,跑Redis服务...

约翰:Redis?

凯文:对,需要消息订阅系统。别担心,就是多个Docker容器的事。

约翰:还要Docker?

凯文:是啊,隔离依赖环境嘛。想要环境可复现的话,还得用Docker Compose,可能还要Fly.io部署,再加GitHub Actions构建流水线。

约翰:这配置...够复杂的。

凯文:这就是现代Web开发啊,兄弟。保持简单嘛。你在干嘛?

约翰:随便玩玩。

(约翰敲了条命令。应用秒启,表单能用,加载飞快,导航流畅。)

凯文:哇,这配置挺复杂啊,用的什么技术栈?

约翰:纯Rails。

直接用Rails不香吗?

评论总结

以下是评论内容的总结:

支持Rails的观点

  1. Rails开箱即用,减少复杂性

    • "Rails is truly batteries-included. Stop with the overengineering" (Alifatisk)
    • "I sorely miss the sheer amount of utility that you can get from Rails out of the box" (Zanfa)
  2. 适合小团队和快速开发

    • "Rails is becoming easier and easier to run complex apps with much smaller teams" (xutopia)
    • "Any project that doesn’t need 30 or more devs... doesn’t need the complexity" (languagehacker)

反对Rails的观点

  1. Rails已过时或不够灵活

    • "these type of Rails posts would’ve been a bit more timely in 2015" (DetroitThrow)
    • "You can’t just 'do Rails' because the UI out of the box isn’t usable" (treis)
  2. 前端生态更强大

    • "You can set up a Vite + React + Tailwind setup with two commands" (bento_n)
    • "Creating reusable stuff... it’s just horrible cumbersome with Rails" (madethemcry)

中立或工具选择观点

  1. 根据需求选择工具

    • "Know your tools and use the best tool for the job" (seandoe)
    • "Tooling isn’t the problem: The complexity is inherent to modern web development" (mkhalil)
  2. 现代开发的复杂性不可避免

    • "modern stacks aren’t complicated because of bad design choices, they’re complicated because they’re living artifacts of collective compromise" (sdotdev)
    • "The whole 'web dev tooling fatigue' is so real" (codegeek)

其他观点

  • 混合方案:推荐Inertia.js结合Rails和React(madethemcry)
  • 怀念简单开发:"the old days of using PHP and Perl with FTP just works" (ksec)

总结:评论中对Rails的评价两极分化,支持者认为其开箱即用、适合快速开发,反对者则认为其过时或前端支持不足。多数人认同应根据项目需求选择工具,并承认现代开发的复杂性不可避免。