4

Is it possible to pass options other than the object into a rabl partial?

For example, the parent template passes an option called "show_field1" to the base template:

extends "base", :show_field1 => true

Then in base.rabl the option could be used like this:

attribute :field1 if @show_field1

The only way I've been able to get at the option is through this terrible approach of looking under the covers:

attribute :field1 if @_options[:show_field1]

2 Answers2

1

RABL supports this by using a special locals Hash:

# some_view.rabl
extends "base", locals: { show_field1: true }

# base.rabl
attribute :field1 if locals[:show_field1]

RABL Documentation on the subject

Nathan Wallace
  • 2,154
  • 4
  • 23
  • 28
0

another way would be to store those values on the top level object and have the extend pick it up in the template.

Thanks for the recco @achiu

Kamilski81
  • 14,409
  • 33
  • 108
  • 161