Module: InheritedResourcesViews::Helper::ClassMethods

Defined in:
lib/inherited_resources_views/helper.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args) ⇒ Object

Creates helper methods from FormHelpers.

module PostsHelper
  text_field :title, :class => 'strong'
  text_area :body
  collection_select :category_id, Category.all, :id, :name
end

From the above code, will be created the following methods: title_form_field, body_form_field and category_id_form_field.



150
151
152
153
154
155
156
157
158
159
160
# File 'lib/inherited_resources_views/helper.rb', line 150

def method_missing(method_name, *args)
  field = args.first

  define_method("#{field}_form_field") do |form, resource|
    if form.respond_to? method_name
      form.send(method_name, *args)
    else
      raise NoMethodError, "This form builder doesn't respond to #{method_name}"
    end
  end
end