Rails World 2026: Custom Rails Generators in RubyEvents (Rachael Wright-Munn) Video: https://www.youtube.com/watch?v=aornGet-EoI Talk page: https://www.rubyevents.org/talks/custom-rails-generators-in-rubyevents Unedited machine transcript, generated with Whisper. It contains recognition errors (names, technical terms). Check the video before quoting. ---- Starting off the right foot there. Hello, everybody. My name is Rachel Wright Munn. And as Michelle said, I am one of four maintainers on the RubyEvents.org team. Now, RubyEvents.org is an open source application where we index Ruby events from around the community using YAML. So this is all of the YAML that's required to describe Rails world 2026. You are here. Okay. So you're probably wondering why we use YAML, and I'm just going to get it out of the way really quick so we can move on to what we're here for. First, it's an inherited architectural decision. Second, it allows us to review events for spam. Third, it allows any developer to update events in the index. And importantly, if our app ever goes offline or is acquired by meetups.com, our data will still persist and be part of the historical record of the Ruby community. Now, using YAML introduces an interesting technical challenge in that data changes require commits. And if we wanted any automation, then I needed a tool that would take unstructured data and turn it into commits. position prior to the age of AI, GitHub Copilot is a tool that will take an issue and convert it into a nice little PR for me so I can scroll blue sky, I can see an update, and then I can fire off a quick agent session and get a PR that I can merge into Ruby events. Spoiler alert, this will work and is how the CFP for Rails World 2026 was added. But it didn't work at first. AI is super smart. It doesn't know our system. It would invent keys. It would use old and deprecated formats like event name which we only use for meetups. It didn't include to-do comments. Our videos file goes through three different phases. The first when the speakers are announced, the second when the schedule is released, and the third when the actual videos are released. Intermediate states like that are challenging for AI to capture because they mostly see the finished result. And the third when the title is used for talks in other languages would be neglected because it was unaware or didn't catch those when it was checking our data. The other problem is it spends lots of tokens understanding examples. We have this problem with contributors as well. We have 180 plus contributors on rubie events.org and increasing all the time. And they have the exact same problem. They're super smart. They have the exact same problem. They have data. They have data that we need, but they don't know the system. They have data that we need, but they don't know our system. They would typo keys and spend lots of time trying to understand our examples. So I had the question, how do I teach them both about Ruby events? For AI, it's kind of a solved problem. It comes down to MCP or skill versus CLI. So an MCP is an AI native SDK that fetches context or executes commands for a model. It's a very specific documentation. It's a very specific documentation. It's a very specific documentation. It's a very specific documentation. It's a very specific documentation. It's a very specific documentation that's discovered by AI that's paired with a normal CLI. Now, MCP tooling is undeniably preferred by AI and it tends to reach for them. But the skill plus CLI, I mean, anybody can use that. We can all read Markdown and then CLIs or CLIs, anybody can call them. Now, one of the biggest arguments that I see in the debate between MCP and skill plus CLI is the context that's consumed in describing an MCP tool. So in the context is tokens. So in the end, I looked at it. So in the end, I looked at it and I made the decision to go with the skill plus CLI, not just for the benefits that are built into it, but also because it allows me to support those 180 contributors and I know that not all of them have tokens. So the next step was picking my CLI format. This is where the generators come into play. So Rails generators are a really familiar pattern. Most of us have run a Rails generator to generate a migration or to get a scaffold and a scaffold and end point. And there was another major benefit. And there was another major benefit, which is that I didn't have to make any of these decisions. Arguments and options, templating and file generation, documentation, testing, and file conflicts which wasn't even on my radar when I started working on the CLI were all handled for me. So I could focus on customizing and working with the actual tooling. As a bonus, I learned more about a fundamental piece of Rails infrastructure. So Rails didn't have to make these decisions either. Rails generators are based on Thor, which is a toolkit for building CLI applications. All right. So we're all together on the same page. I want to make a generator to make my YAML files that describe events. So let's start. I'm going to generate a generator because, of course, there's a generator to generate your generators. It's going to give us all of these files. It's going to give us a CFP generator. It's going to give us a CFP generator. It's going to give us a CFP generator. It's going to give us a CFP generator test. It's going to give us a CFP generator test. It's going to give us a CFP generator test. You might be wondering, how does it name things? Because it's weaved that CFP through pretty thoroughly. And the first hint is in the class that it generates with for the CFP generator named base. So named base takes one argument and then it has all of these methods associated with it that output different versions of CFP. We can actually take a look at the argument. We can take a peek at the argument and see that it says argument name type string. And then, oh, it gave us even more methods. That's fun. Let's take a cheeky little peek at how those are defined in Rails. They're pretty straightforward, mostly string interpolation. And, oh, it gave us even more. Wow, we got so many methods from named base. Let's throw all of that away. So I don't need a name. I know where I want my file to be. And I don't need any of those helper methods. So we're going to do that. So we're going to substitute named base for base here. Let's kind of summarize the differences between these. So named base is going to accept one argument name. It gives you tons of simple helper methods based on the name. And it inherits from base. Base has none of that. And it's the one that I picked. Now, I mentioned that we have that argument name. That's how a CLI will accept input. There's actually two ways to do it. There's arguments and then there's options. So you have argument event type string, description event slug. And then when you're calling the CLI, it just goes bin reels gcfp, reels row 2026. And the options can be either required or default and it's dependent on order. So you can think of this a lot like positional arguments in a method. Next, we have options. So the class options is structured almost exactly the same, but with class option instead. And what you can see is that when we call the CLI, we now have this flag event that we're passing the value. This means that we have this flag in the line too. This means that it can be required default or optional and it's order independent. So you can think of it like the Clark Center method. So if I'm looking at these two options, for me, I'm going to go with the options because I feel like that makes it easier for my contributors and agents to avoid issues with ordering. And it gives me a lot more flexibility when I'm deciding what values I want to pass into it and exclude. I'm going to go here and I'm going to add all of the class options that I need to describe a CFP to my generator. So there's some little extras in here, like the aliasing and the banner that I don't have time to describe today. But these options do something else that's really cool. Have you ever called help on one of the default generators? I didn't know this existed before this, but there's documentation for each of the generators. If we look at this section here, our class options have generated the generated documentation based on that. And every time we update those class options, these are also going to get updated. And if you map this back to the description of class options that I had before, you can kind of see that you can see that laid out here. There's something else in here that looks kind of familiar at the bottom. This is our usage documentation. It gets appended to the end of our help call. And this is our usage file. And this is our usage file. This is our usage file. So let's time travel to the present. So let's time travel to the present. This is the modern-day help doc or usage file for the Ruby event CFP generator. We've got a couple of different sections in here. I've got this minimal example. And then I've got an example about how to generate an ongoing meetup CFP. So for our meetups. We've got an end date. I've got one for lightning talks. I've got one for lightning talks. And then I've got another one that's about how to update or extend the CFP. Because again, capturing those changing states is a bit challenging when it comes to AI. So all of this context just gets automatically injected when I have it called help. Humans struggle with reading documentations too, but honestly, I didn't even know this documentation. So I'm not sure how much it helps with that. All right. All right. All right. All right. All right. All right. We've got our inputs. We've got our documentation. It's time to generate some files. So we're going to start with real world. Rails world 2026 CFP. I'm going to take this and I'm just going to paste it into our TT file. This is our template file. TT stands for Thor template. And then these Thor templates just use regular ERP. And then we're going to go here and replace each of those sections. And then we're going to go here and replace each of those sections with the ERP tags and then the options. And that's our template. By the way, you can customize the templates for the default generators as well. There's an entire section for it in the Rails guide for generators section six. But basically you go into lib templates and you can replace those default templates. And most of them use name base. So you have access to all of the helper methods that I showed you before. All right. All right. All right. All right. So now it's time to actually use the template that we created. So we're going to introduce two new methods to our generator. We're going to introduce CFP file path and create CFP file. Create CFP file is pretty straightforward. We have template. And then we pass in our template file. And then we pass the destination we wanted to end up in. Now you might be wondering how it knows where to find our template file from. And the answer is in the generator that was generated. At the very top, it added source root. And then file. And then file. And then file. And that's one of the things generators are really good at. And that's one of the things generators are really good at. And that's one of the things generators are really good at is capturing blue code like that that needs to be added in. The destination is something that I added. So in Ruby events, we store all of our CFPs in data folder and then event series and then event. And then we have this destination route, which is passed in by Rails and defaults to where the generator was called. Let's do that now. Let's actually run the generator that we've just created. So we're just created. All right. All right. So we're going to run this. And it's going to create it. And it's going to work. And it's going to pass in like all of the values that we asked for. And this is the output of that. So we have just created a working generator. Yay! I think next I mentioned that we have those ongoing meetup CFPs. I think we should try calling this generator without that start and end date and seeing what happens. Oh. So I forgot we already had a CFP. YAML created. So we ran into a file conflict. But thankfully, template has native support for file conflicts by default. So it's going to pop this up and I can just say, yes, overwrite. Oh. Okay. So in Ruby events, if we pass an open date and a closed date, we need to have values in there and they need to be formatted as a date. So we're going to have to remove those fields from the template. All right. So I'm going to go here and I'm going to say if I have options open date and I'm going to pass that. And again, this is just regular herb, which you're already familiar with from your template. And then I'm going to do the same thing for options closed date. And it's going to look like this, which is good and passes validation, but it has a bunch of weird extra white space at the bottom. Normally when I'm working with like HTML, ERB, all of that kind of gets smooshed out by the browser and I don't have to see it. All right. So instead, what I'm going to do is I'm going to use ERB minus tags in order to remove that extra white space that was added. Okay. That looks much better. And now I only have one extra line at the end. So we trimmed white space using these ERB minus tags. But now we have some conditional logic. So I think it's time for us to write a test. All right. So good thing we created one, the CFP generator test. I'm just going to uncomment the code here and run it and see what happens. And there we go. And there we go. And there we go. And there we go. Uncomment it and run it and green dot. Yay. It says no value provided for required options event. So I think we should probably pass some options to this. Okay. So when I'm calling run generator, I'm going to pass an array that are the exact values that I would have passed to my CLI. And what I like to do is I like to pair them with flag and value just to make it easier to read. So let's go. All right. All right. All right. All right. All right. All right. All right. All right. All right. Let's run this again. Green dot. Not bad. Maybe we should try like asserting the file. So assert file is another testing helper that's provided by Rails. We're going to put our file path in here and then we're going to take content. A really common pattern is just checking this against kind of some rejects. But you can do whatever you want to assert content. And green dot. Green dots don't inspire much confidence. Good news. Good news. Good news, though. If we go to temp generators, we can actually see the file. It persists after the test run. Wait. If it persists, why doesn't it run into a file conflict like we saw earlier? That's kind of weird. Let's take a look at what that test is actually doing. All right. So this is the default generator test that it created. We've got this destination here where we put in temp generators. That explains why the file was in temp generators. And when I did the cfp file path. I passed in destination route. That's how it ends up knowing the temp generator goes there. Okay. Good. And then set up prepare destination. This must be what does the cleanup. Oh, wow. That's so straightforward. We just remove the entire destination route folder and then remake it. Perfect. Wait. Hang on. If we're removing the temp generators, and then recreating that, and then recreating that. Wouldn't this be flaky if we had parallel test cases? Yeah. Yep. Yep. Yep. Yep. Yep. Yep. Yep. Yep. Yep. Yep. Yep. Yep. Yep. Yep. And he just uncommented that and like rolled forward. Then I suppose at some point you might end up with flaky generator specs. So instead, I recommend this. When you're setting your class's destination, use a temp directory. That way you don't run into the same errors and you don't end up running into the same issue. And you don't end up running into that same issue. And then the other thing I recommend cleaning it up. And then the other thing I recommend is cleaning it up in Teardown. We've been using this in Ruby events for a while and we haven't had any issues with it. So just a reminder, when you're working with those tests, try and use Ruby's temp directories as the destination and cleanup in Teardown. But now I can't see the file, right? And so I'm back to my original asserts and confirmation. I'll just put a binding.irb in here. No big deal. And then I'll go check the file. And then I'll go check the file that way. Perfect. Perfect. Okay. So we can actually see our temp directory. And it worked. That's great. Let's go back to the console. And where did my green dog go? Where's my binding.irb? Hang on a second. Let me just do like a control C, maybe a little quit, panic. Okay. Quit plus enter got me out of that mess. That's weird. That's so weird. And you can see the IRB output now that I've done put and enter. It's almost like it captured my binding.IRB output. And you might be baffled by this if you didn't read section 10 of testing Reels generators very thoroughly. It turns out that you need to pass Reels log to standard out true in order for your debugging tools to work. All right. Let's try that out now. Perfect. Okay. That makes so much more sense and everything looks fun and I can see it now. Good. So, oh, wait. Why don't we do that for everything? Well, if I run it on the current test file. Well, if I run it on the current test file that we have in Ruby events, this is what one of our tests look like. So if you're not capturing that output, it's going to look really messy when you're running your entire test suite, which is why we need that Reels log to standard out true. Okay. So the roundup of the feedback for testing generators is make sure to use Reels log to standard out true to C output. Replace your destination route with a temp directory. And then don't prepare destination. All right. All right. I have now taught you enough about generators to be dangerous. There's a lot more to learn about generators. There's a lot more to learn about generators. There's a ton that I couldn't cover. I strongly recommend Garrett's blog. Obviously, I recommend the Rails guides. They're fantastic. But also, the Ruby events generators are open source. It's an open source. Rails is open source. Rails is open source. You can go look at Rails. Rails is open source. You can go look at Rails as generators and read them and see what their testing patterns are and how they handle things. Okay. So we have spent an awful lot of time on the COI. So I think it's time for us to start talking about the skill part of that equation. Skills are pretty straightforward. We start with front matter about how to use it. Then it's just regular markdown. I like to include important notes about things that the AI commonly gets wrong. So we have to use it. So we have to use it. So we have to use it. So we have to use it. So we have to use it. So we have to use it. So we have to use it. So we have to use it. All right. So that's the skill part of skill plus CLI. All right. So that's the skill part of skill plus CLI. And now we've done it. We built the thing. We built the thing. We built the skill. And we built the CLI. We have handled the or part of this equation flawlessly. And really, we're done. It's fine. I don't need an MCP. I have the skill plus CLI. I said or NPC. What if it were MCP? What if it were MCP? What if it were MCP? What if it were MCP? So at RubyConf, Andy did this talk about abusing schemas using meta programming where he talked about how to use an open AI schema in order to generate a Ruby LLM MCP tool. So I was delighted and excited and I wanted to pair with him, and we did, to build MCP tooling for our generators. We have these really specified class options. That describe everything that we need for an MCP tool. And yeah. So the full story is on the Ruby on Rails podcast. If I don't have time for class options, I don't have time for this story eventually. But we now have a tool generation script that will take a CFP generator or any generator and turn it into a Ruby LLM MCP tool for our server. It's a CLI and an MCP. I haven't even got to the best part. Any time we merge generator changes. Any time we merge generator changes, it's reflected in MCP tools when we restart the server. It's so nice. But this also means that I can actually test skill plus CLI versus MCP. Which is what I did. So I started with GPT 5.4 and I deleted all of the improvements that I made to the codebase and started rolling them back in slowly. The first one I had was I had no skill. I had no skill, no MCP, just trusting the AI. I told it to add Rails world 2026 and then I gave it a markdown file. I wanted to make sure that it was consistent and different web fetches weren't affecting my results. And then I also used bin rails validate all to validate because that could have a major impact on our results as well. Because it pulled in that old context and decided to use old sponsor logos from 2023 instead of the 2026 ones, it got one password lowered and said one password. Table check instead of one password. Table check instead of table check instead of table check. And it added a URL for the Palmer event center which tells me that it decided to do a web fetch that I didn't authorize. I'm going to count that as four errors and it cost me $1.83 and 136,000 tokens to do that. Now this next one, I didn't add the skill yet. I just added the generator. So this is the status that you are in with the Rails generators right now. Using custom generators at Rails world 2026, and everything else is the same, and everything else is the same. This time it only had two errors. This time it only had two errors. It forgot planet scale and it replaced m dash with hyphens for descriptions. So you can tell the big AI companies are really listening to us. This one was 131,000 tokens and two errors. And then this last one, we're finishing the skill plus CLI. And this time it only had one error, which was replacing the m dashes with hyphens. So you can see how the MCP went. And no videos, no schedule, no sponsors. It just kind of quit in the middle of the run. So that was a fun thing to discover. However, it was the lowest cost and the lowest token usage out of all of the options. I didn't just run this with a Frontier model, though. I ran it with a smaller sibling, too. So in this one, the worst one was no tool. So it was no tool. So it renamed the keynotes. So it renamed the keynotes. None of the talks. None of the talks had descriptions. And for the schedule, it decided to use the format we used for lunch and breaks for everybody's talks so they wouldn't link. Generators, but nothing else. It copied involvements, including the old MC and volunteers. It deleted all the to-dos and added the event name parameter that I mentioned before. And yeah, for the MCP one, that one was pretty good. That one was pretty good. It did add an involvement. It did add an involvement, which was kind of a problem, but it was just the Rails foundation, so that's better. And then it also did our m dash for hyphens mistake. The interesting one to me, however, is 39 cents for zero mistakes. Because I was starting to see kind of a pattern here, which was that smaller models with better tools outperformed larger models for scope and repeatable tasks and repeatable tasks. Because they didn't go off script. They didn't go off script. They didn't try and rewrite my descriptions. They didn't try to look at other files to decide if the file that the generator had created was appropriate. Which brings us to something very interesting. The Rails foundation recently published a set of model, they did an AI model report and they found that Luna, which is right over there, had a shockingly good accuracy and it was a lot of the way. So, I wanted to see the data. So, I wanted to see the data. So, I wanted to test that one as well. Okay, it had a lot of trouble with schedules. At the earlier ones, it would do wrong times. It had no schedule for the MCP option. And for the skill plus CLI, the only error that it had was that it didn't include day zero in the events. And then the other errors were all related to replacing either descriptions with one line summaries. And for the MCP. And for the MCP. And for the MCP. And for the MCP. And for the MCP. And by the way, all of these together are less than a quarter. So, I had a few conclusions after this. Skills had fewer mistakes but were more expensive. The cost of MCP tooling might be overblown because MCP tooling was one of the lowest options in all or one of the lowest cost options for all of the world. And then there are more. And then there are a couple of these. And then there are a couple of takeaways I'd like to leave you with. One is you're now dangerous enough to build a custom generator. I'd like you to remind your agents to use Rails generators to get more reliability and to lower your token costs. I think you should try using a small model with better tools instead of leaving things to Opus all the time. I think you should try customizing existing generator templates for your company's standards to see if you can get closer to what you're looking for. What you're looking for. What you're looking for in a first pass. And then the last one is to make sure that you build for humans too. Humans and AI need help understanding our code basis. So let's make sure that as we're building, we build tools for both. I want to thank you all so much for your time. My name is Rachel Reitman. I go by Chael or Rachel. You can find me at Chael Codes and all the places. I stream on Twitch and YouTube Sundays at 1800 UTC. Thank you. you