StatusCode: Our Weekly Programming Newsletter. You're not just a Rubyist, you're a software developer, right? :-) Check out StatusCode Weekly, our language and architecture agnostic newsletter that covers the biggest news across the entire software development world.

RubyFlow The Ruby and Rails community linklog

×

The Ruby and Rails community linklog

Made a library? Written a blog post? Found a useful tutorial? Share it with the Ruby community here or just enjoy what everyone else has found!

Dynamic Form Options With Hotwire Turbo Frames

I needed a way to dynamically show and hide form options based on what a user selects and wanted to use Turbo Frames. The benefit being all of the logic can be in the erb file of what to show and hide based on the current state of the model.

This works by calling a Stimulus controller posting the unsaved form to your controller and reloading the frame the form is in. The stimulus controller adds a hidden form value to tell the controller to use mode.attrbutes = instead of update so the changes are not saved in the database and then edit action is render again and reloaded into the form frame.

I attempted to create screencast to show the method I used to do this. I would consider it a beta since it’s my first attempt at a screencast :slight_smile:. I’m also using a similar method to add/delete items from a nested has many releationship which I will do a screencast on as well if anyone finds this first one helpful.

Watch Screencast View Sample Code

Post a comment

You can use basic HTML markup (e.g. <a>) or Markdown.

As you are not logged in, you will be
directed via GitHub to signup or sign in