Skip to content

Extending console show_for

Petr Marek edited this page Mar 11, 2019 · 1 revision

To DRY up the code, add config/initializers/show_for.rb extending ShowFor::Builder with your custom methods.

i.e.

# config/initializers/show_for.rb

class ShowFor::Builder
  def artists
    attribute(:artists) do
      if object.persisted?
        object.artists.collect do |artist|
          template.link_to(artist.last_name,
                           template.main_app.url_for([:edit, :console, artist]))
        end.join(', ').html_safe
      end
    end
  end
end