← Back to Upcase

Ruby Science: Introduce Parameter Object | Upcase

(Upcase ) #1
Melanie joins Joe to demonstrate a simple (but useful) pattern: Parameter Objects. Melanie replaces a long parameter list with one object in a single bound! Try it for yourself in our refactoring trail.
This is a companion discussion topic for the original entry at https://thoughtbot.com/upcase/videos/ruby-science-introduce-parameter-object

(Anthony Lee) #2

This was great lesson @jferris. One quick question…

I have a form that requires a lot of parameters. What would be the best way to refactor if you have like 40+ fields?

class SomethingsController < ApplicationController
  before_action :authenticate_user!

  def index

  def show

  def new

  def create

  def edit

  def update

  def destroy


  def somethings_params
      :and_so_on..... 40+ more

(Joe Ferris) #3

If you have a crazy huge form, you can use composite form objects. You can make several form objects, each of which represents a set of fields on the form. Each can define which fields it requires and define validations that make more sense on the form than they do in your models. You can then define a higher-level form object that doesn’t accept fields, but instead composes the individual form objects which handle their own fields.

(Zaid Al Lahham) #4

Hi @mrgilman, great lesson!
I was wondering what command you use to maximize the rspec pane in tmux when you want to see the whole pane. I noticed you do this is when you usually see a failure and you want to see the whole message rather than just the number of failures at the bottom.

(Jack) #5

It was probably LeaderZ, which zooms the focused pane.