-
Notifications
You must be signed in to change notification settings - Fork 5
ViewModels#model_reader
Either you explicitly call the model, like so model.some_attribute, or you install model readers.
Model readers are just delegates to the model, with the added functionality that they can have filters on them, like the h method, or upcase for example.
model_reader :first_name, :last_name
Creates two delegate methods first_name and last_name that delegate to the model.
Calling first_name in the view model will simply give you the model value.
model.first_name # => "Joe"
view_model.first_name # => "Joe"
model_reader :description, :filter_through => :h
Creates a description delegate method that filters the model value through h.
Calling description in the view model will give you the html escaped model value.
model.description # => "<script & more>"
view_model.description # => "<script & more>"
model_reader :description, :filter_through => [:textilize, :h]
Creates a description delegate method that filters the model value through first textilize, then h.
model_reader :first_name, :last_name, :filter_through => [:textilize, :h]
Creates both a first_name and last_name delegate method that filters the model value through first textilize, then h.
Note: Filter methods can be any method on the view_model with arity 1.