Class: Zombie
- Inherits:
-
Object
- Object
- Zombie
- Defined in:
- lib/rails_zombie.rb
Instance Method Summary collapse
-
#initialize(controller) ⇒ Zombie
constructor
A new instance of Zombie.
- #set_inner_instance_variable(model_klass_name, id) ⇒ Object
- #set_nested_resources_instance_variables ⇒ Object
- #set_resource_instance_variable ⇒ Object
Constructor Details
#initialize(controller) ⇒ Zombie
Returns a new instance of Zombie.
3 4 5 |
# File 'lib/rails_zombie.rb', line 3 def initialize controller @controller = controller end |
Instance Method Details
#set_inner_instance_variable(model_klass_name, id) ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/rails_zombie.rb', line 17 def set_inner_instance_variable model_klass_name, id begin klass = model_klass_name.constantize end instance_variable_name = model_klass_name.underscore instance_variable_value = klass.find_by_id(id) @controller.instance_variable_set("@#{instance_variable_name}", instance_variable_value) rescue #model not found end |
#set_nested_resources_instance_variables ⇒ Object
11 12 13 14 15 |
# File 'lib/rails_zombie.rb', line 11 def set_nested_resources_instance_variables nested_models.each do |klass_name, id| set_inner_instance_variable(klass_name, id) end end |
#set_resource_instance_variable ⇒ Object
7 8 9 |
# File 'lib/rails_zombie.rb', line 7 def set_resource_instance_variable set_inner_instance_variable(@controller.class.name.gsub("Controller","").chop, @controller.params[:id]) end |