Module: Waves::Helpers::Model
- Included in:
- Default, Renderers::Scope
- Defined in:
- lib/helpers/model.rb
Overview
Model helpers allow you to directly access a model from within a view. This is useful when creating things like select boxes that need data from anther model. For example, a Markaby select box for authors might look like:
select do
all(:user).each do |user|
option user.full_name, :value => user.id
end
end
You could also use these within a view class to keep model-based logic out of the templates themselves. For example, in the view class you might define a method called authors
that returns an array of name / id pairs. This could then be called from the template instead of the model helper.
Instance Method Summary collapse
-
#all(model) ⇒ Object
Just like model.all.
-
#find(model, name) ⇒ Object
Finds a specific instance using the name field.
Instance Method Details
#all(model) ⇒ Object
Just like model.all. Returns all the instances of that model.
22 23 24 |
# File 'lib/helpers/model.rb', line 22 def all( model ) Waves.application.models[ model ].all( domain ) end |
#find(model, name) ⇒ Object
Finds a specific instance using the name field
27 28 29 |
# File 'lib/helpers/model.rb', line 27 def find( model, name ) Waves.application.models[ model ][ :name => name ] rescue nil end |