alphagov / learningtime-ph-sem1

Early talent assigned learning time semester 1 project for Peter Hattyar
0 stars 0 forks source link

Generate the backbone MVC for a Rails app #1

Open PeterHattyar opened 1 year ago

PeterHattyar commented 1 year ago

As a first step, I'd like to have an MVC skeleton set up for a Rails Application as a sort of initial 'bed' for this project.

WHAT

A standard Rails MVC structure

WHY

So I get the basics down for a simple Rails application utilising the Rails framework's generator feature.

Acceptance Criteria

huwd commented 1 year ago

I got a lot of value out of this tutorial. The start of it is free, but we may have L&D budget if you speak to your line manager: https://3rd-edition.railstutorial.org/

There are other free alternatives, but this might be a helpful starting point

huwd commented 1 year ago

Other things to consider. What version of Ruby do you want to run? How will you make that choice?

What version of rails would you like to target? Again why that, and not any others?

PeterHattyar commented 1 year ago

@huwd I tried to think about it and am aware that there are lot of version differences, which are managed by dependency upgrades on repositories in some cases, while in others certain versions of dependencies are locked in place. Given this is something I try to build from the ground-up, I've decided to use the latest Rails version available with its current set of gems.

Would you be able to give a quick insight and/or hints and tips how a dev should consider which version of rails (or anything in general required for a project for that matter) to select, and how to decide on for and against? In my mind, I'd take into account what platform, purpose and user-base I create the application for, and see if I can find any information about what rails version is preferred/supported in a specific scenario, but that's as far as I can think of as a start.

huwd commented 1 year ago

Yeah this is a constant question, I think the important thing here is to be clear on the process for getting an answer more than what version you actually end up doing.

Here's what I'd do.

  1. Forget I know anything about rails: or specific features in versions 😅 (I'll come to why later!)
  2. Establish what versions exist: Visit the website for the tool I'm interested in (could be node.js or ruby, or rails), and find the releases pages - be clear on what versions are actually out there.
  3. Look at Major versions: Most places use semantic versioning, which means for your purposes you can generally ignore everything apart from the first number. You are interested in Major changes (the first bit), ones that after you make a choice you might not be able to roll back from because there is a fundamental incompatibility. So you might look at rails and think "OK so there are basically v5, v6 and v7). Now you know what's out there.
  4. Look at how recent the most up-to-date major one is: Look at the most recent one, work out how recently the major version was published. If v7 of Rails was published last Tuesday, then 🤔 perhaps pause for thought. We generally trust these folks to do a good job releasing stable software but you're close to the bleeding edge there. So you may want to 🤔. In our case it looks like Rails version 7 has been around since 2021, so hopefully they've ironed out any massive issues. If we're in doubt, defaulting to the latest stable release is a pretty good idea.
  5. How much longer does a version have in support? This isn't so much an issue for Rails, but if you look at something like node.js there are multiple version in support at once, some have a "Long Term Support" option. Those are often a good bet. Mostly you just want to make sure if you pick a version it's not either out of support (and so not getting security or other updates), or that it's not coming an end of support before your project finishes. For rails v7.1 doesn't have a release date yet and I don't think anyone is talking about v8.0 yet. So v7.0.x seems safe!
  6. What are your peers using: Now you know the landscape, look at what those around you are using, you can usually find a version pinned in a Gemfile, or in a Gemfile.lock. Here's a few forms-admin, frontend (which runs the GOV.UK home page), Whitehall (GOV.UK's big publishing app). I'd say in the absence of any better idea try and use what your peers are using, it'll mean you can borrow more code from them there's less that's unexpected if someone starts working on your code, and that upgrading your app can likely be done along with everyone else's.

I think when you've done all that, a clear winner will appear here for both Ruby version and Rails versions.

After that everyone other dependency you can probably just default to taking the "latest" version, as it should be less consequential (though there are exceptions to that statement we can get into later).

The important this about this is that you are mostly making this decision based on the non functional requirements for your app (what's secure, what's up-to-date, what's easy to maintain).

Rails 7 also has some great new features, and there's good reasons to use it over Rails 6 for just making fun stuff. But when you are starting out, I suspect you will not know those are features you really want just yet. Or you might like the sound of them, but then end up focused on building something that never uses them. I'm really interested in turbo-rails and stimulus, they sounded cool in rails v7. But I've never had a chance to actually use them, so if I'd upgraded to get those features it would have proved a big distraction. Best to just stick to the fundamentals above.

Only other factor you might want to have a quick google around for is "what gets me the most help". There was a big split in the Python community for a while around v2 and v3.

At some point, you've got to learn a lot here, and it's helpful if there are lots of blogs around around that are using the same version of your code. When i was learning rails there were a ton of resources for v5.x, and then v6.x came out. Some blogs never updated, so for a while I kept on using v5 just so I could make progress.

However you have the advantage of working in an organisation with folks around you using rails, so your key "learning resource" will be your peers, That's why that step 6 is important if you are building a GDS project.

If it's a hobby weekend project then 🤷🏻 perhaps factor in what there are good blogs on too.

Hope that helps, and hope that helps explain how you'd answer that question as much as gives you a lead on which actual version to run!