6 ms·
The answer is probably that parts of Rails are worth knowing, and other parts aren't. ActiveRecord and the Rails Controller/Model/Routing system are as good as
by tptacek 8y ago
The answer is probably that parts of Rails are worth knowing, and other parts aren't.
ActiveRecord and the Rails Controller/Model/Routing system are as good as anything in the serverside framework world. A few years back people might have started saying that AR was in danger of being obsoleted by "modern" databases, but SQL (and particularly Postgres) has come roaring back, and AR remains one of the best (arguably the best) SQL ORM.
At the same time, there's a lot of mechanism in Rails that is aimed at front-end work; templates, different template engines, helpers, the inscrutable asset pipeline. This stuff, not so much anymore. The energy you'd put into learning how to do idiomatic front-end in Rails, you should instead put into something like React (probably: into React).
People with a visceral "No" reaction to your question are probably thinking of what would happen if you started with a couple Rails books and tutorials and just went to town building a 2012-era idiomatic Rails application. Don't do that! But as an API server backend, Rails is fine, and does some things better than other platforms.
For whatever it's worth: we see a lot more Django today than Rails. 5 years ago, it was the opposite. People probably wouldn't recoil at the prospect of you doing an idiomatic Django application, even though it's not that much different than an idiomatic Rails application.
- briandear 8y agoWhy React over rails front-end? It seems like it adds undue complication. What’s the real benefit? Basecamp works great and it’s a rails front end. Rails make full stack development pretty easy.
- hosh 8y agoReact buys you two things: (1) reusable components (2) React Native https://thinkster.io/tutorials/what-exactly-is-react https://thinkster.io/tutorials/what-exactly-is-react It's major criticism: there is a kernel of truth in the joke that React is a dressed-up PHP (in the sense of how you put the components together) Some other options are Vue and Elm.
- tptacek 8y agoIt's been a long time since I wrote or even had to look at PHP, but I have done work in PHP. I use React constantly. I do not see any similarities between the two, like, at all.
- hosh 8y agoYeah, I was shocked when I first heard of it. But when I thought it about it, it makes sense: https://www.reddit.com/r/reactjs/comments/58wmnz/so_reactjs_is_basically_just_clientside_php/ https://www.reddit.com/r/reactjs/comments/58wmnz/so_reactjs_...
- hosh 8y agoHere's another comment from that reddit thread: "If you're at all familiar with the history of React, there's actually some amount of truth to this. React grew out of an internal PHP extension at Facebook called XHP. See the recent post describing React's history at https://facebook.github.io/react/blog/2016/09/28/our-first-50000-stars.html https://facebook.github.io/react/blog/2016/09/28/our-first-5... for more details." "That said, the parallels only go so far. PHP is frequently rather unstructured, while React lends itself to some very specific structures. I don't think I'd necessarily say that PHP typically involves "recursively breaking down parts of the page". But sure, some similarities. (Then again, just about anything that involves template-ish work has some similarities... )"
- tptacek 8y agoThat blog post section describes JSX, not React. JSX is just a notation.
- hnzix 8y agoYou can have the best of both worlds and use webpacker to mix React or VueJS into the Rails frontend where it makes sense, eg complex forms or widgets. Many webapps are not Facebookish and don't need to be SPA blobs, with all the additional complexity, SEO and accessibility costs.
- dyeje 8y agoIt really depends on the application. If you're making something that has a highly interactive UI, then React is a great tool for that. It doesn't have to be all or nothing though, you can use Rails server side rendering with React components for the complicated stuff. Basecamp is not a fair comparison, they use Stimulus which is their own frontend framework.
- rst 8y agoWorth noting that webpack (via the webpacker gem) is supported in Rails 5.2, and will be default in Rails 6; using that gets you access to current versions of React, Redux, and pretty much anything else packaged as npm modules. You still need some kind of view layer to serve up the pages that invoke the JS, but if what you're doing is a single-page app that's almost all React, then that view layer doesn't actually have to do very much.
- ksec 8y agoI wonder why Rails 6 doesn't go all in on Webpack and drop Sprockets.
- matthewmacleod 8y agothe inscrutable asset pipeline This has basically all been replaced by Webpack so I’m not so sure
- philwelch 8y ago> A few years back people might have started saying that AR was in danger of being obsoleted by "modern" databases, but SQL (and particularly Postgres) has come roaring back, and AR remains one of the best (arguably the best) SQL ORM. To me, that gives me pause about the viability of ORM as an approach more than it vouches for Rails. ActiveRecord has so many limitations and footguns that using it as a serious production framework is...well, doable, if you're willing to do a lot of the work that ActiveRecord claims to save you from.
- tptacek 8y agoPeople have been saying this about ORMs since the original Rails Blog Demo introduced ActiveRecord, but I don't think we even have to engage with the argument, because no industry trend has made ORMs less relevant; instead, the sort-of collapse of the NoSQL trend has, if anything, made them more relevant. If AR was useful 5 years ago, it's useful now. If you're going to try to tell me that there's a countervailing trend of people meticulously writing their own SQL statements and record serialization logic, I'm going to say no, I haven't seen anything like that in our client base, or in blog posts, or anywhere else. Incidentally, lest I come off as a Rails partisan: I don't use it anymore; the last thing I built with Rails (Microcorruption) was in 2013. But I sort of do miss ActiveRecord sometimes.
- philwelch 8y agoI can't speak to the broader state of the industry as you can. I don't know what the trends are. I'm just not actually sure what problem ActiveRecord actually solves. If you don't want to write SQL and you're willing to live with a certain degree of inconsistency in your data, that's what NoSQL is for. If you actually want the benefits of a SQL database, ActiveRecord makes the easy things easy and the difficult things impossible unless you just give up and write SQL, which you could have just done in the first place and wouldn't have actually been that much harder. It's entirely possible that everyone does the same thing that I did when I worked on Rails apps: manually add all the DB constraints the ActiveRecord documentation tries to talk you out of, write my own error handling code for when these constraints threw exceptions that ActiveRecord had no idea how to handle, liberally call 'connection.execute' or 'find_by_sql' when nothing I wanted to do cleanly fit into the ActiveRecord query interface, and so on. It's also entirely possible that some ORMs other than ActiveRecord does a much better job at these things, but I'm taking you at your word that AR is the best.