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’
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'app/helpers/effective_resources_helper.rb', line 141 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) safe = atts.delete(:safe) 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) return render("form_#{action}", atts) end if lookup_context.template_exists?('form', controller._prefixes, :partial) return render('form', atts) end effective_resource.view_paths.each do |view_path| if lookup_context.template_exists?("form_#{action}", [view_path], :partial) return render(view_path + '/' + "form_#{action}", atts) end if lookup_context.template_exists?('form', [view_path], :partial) return render(view_path + '/' + 'form', atts) end end # Will raise the regular error return ''.html_safe if safe render('form', atts) end |