Method: EffectiveResourcesHelper#render_resource_form
- Defined in:
- app/helpers/effective_resources_helper.rb
#render_resource_form(resource, atts = {}) ⇒ Object
When called from /admin/things/new.html.haml this will render ‘admin/things/form’, or ‘things/form’, or ‘thing/form’
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'app/helpers/effective_resources_helper.rb', line 133 def render_resource_form(resource, atts = {}) unless resource.kind_of?(ActiveRecord::Base) || resource.class.ancestors.include?(ActiveModel::Model) raise 'expected first argument to be an ActiveRecord or ActiveModel object' end raise 'expected attributes to be a Hash' unless atts.kind_of?(Hash) effective_resource = (atts.delete(:effective_resource) || find_effective_resource) action = atts.delete(:action) atts = { :namespace => (effective_resource.namespace.to_sym if effective_resource.namespace), effective_resource.name.to_sym => resource }.compact.merge(atts) if lookup_context.template_exists?("form_#{action}", controller._prefixes, :partial) render "form_#{action}", atts elsif lookup_context.template_exists?('form', controller._prefixes, :partial) render 'form', atts elsif lookup_context.template_exists?('form', effective_resource.plural_name, :partial) render "#{effective_resource.plural_name}/form", atts elsif lookup_context.template_exists?('form', effective_resource.name, :partial) render "#{effective_resource.name}/form", atts else render 'form', atts # Will raise the regular error end end |