Class: Resourcerer::Strategies::OptionalStrategy
- Inherits:
-
DefaultStrategy
- Object
- Resourcerer::Strategy
- DefaultStrategy
- Resourcerer::Strategies::OptionalStrategy
- Defined in:
- lib/resourcerer/strategies/optional_strategy.rb
Instance Attribute Summary
Attributes inherited from Resourcerer::Strategy
#config_proc, #controller, #name, #options
Instance Method Summary collapse
Methods inherited from DefaultStrategy
#build_resource, #finder_param
Methods inherited from Resourcerer::Strategy
Constructor Details
This class inherits a constructor from Resourcerer::Strategy
Instance Method Details
#find_resource(id) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/resourcerer/strategies/optional_strategy.rb', line 11 def find_resource(id) if config.optional model.where(finder_attribute => id).first else model.find_by(finder_attribute => id) end end |
#id ⇒ Object
19 20 21 |
# File 'lib/resourcerer/strategies/optional_strategy.rb', line 19 def id @id ||= params[finder_param] end |
#resource ⇒ Object
7 8 9 |
# File 'lib/resourcerer/strategies/optional_strategy.rb', line 7 def resource find_resource(id) if id end |