Module: ActionView::Helpers::RenderingHelper
- Defined in:
- lib/active_scaffold/extensions/action_view_rendering.rb
Overview
:nodoc:
Instance Method Summary collapse
-
#render_with_active_scaffold(*args, &block) ⇒ Object
Adds two rendering options.
- #view_stack ⇒ Object
Instance Method Details
#render_with_active_scaffold(*args, &block) ⇒ Object
Adds two rendering options.
render :super
This syntax skips all template overrides and goes directly to the provided ActiveScaffold templates. Useful if you want to wrap an existing template. Just call super!
render :active_scaffold => #ActionView::Helpers::RenderingHelper.controllercontroller.to_s, options = {}+
Lets you embed an ActiveScaffold by referencing the controller where it’s configured.
You may specify options for the embedded scaffold. These constraints have three effects:
* the scaffold's only displays records matching the constraint
* all new records created will be assigned the constrained values
* constrained columns will be hidden (they're pretty boring at this point)
You may also specify options for the embedded scaffold. These only do 1/3 of what constraints do (they only limit search results). Any format accepted by Sequel::Model.find is valid.
Defining options lets you completely customize the list title for the embedded scaffold.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/active_scaffold/extensions/action_view_rendering.rb', line 46 def render_with_active_scaffold(*args, &block) if args.first == :super last_view = view_stack.last || {:view => instance_variable_get(:@virtual_path).split('/').last} = args[1] || {} [:locals] ||= {} [:locals].reverse_merge!(last_view[:locals] || {}) if last_view[:templates].nil? last_view[:templates] = lookup_context.find_all_templates(last_view[:view], last_view[:partial], [:locals].keys) last_view[:templates].shift end [:template] = last_view[:templates].shift view_stack << last_view result = render_without_active_scaffold view_stack.pop result elsif args.first.is_a? Hash and args.first[:active_scaffold] require 'digest/md5' = args.first remote_controller = [:active_scaffold] constraints = [:constraints] conditions = [:conditions] eid = Digest::MD5.hexdigest(params[:controller] + remote_controller.to_s + constraints.to_s + conditions.to_s) session["as:#{eid}"] = {:constraints => constraints, :conditions => conditions, :list => {:label => args.first[:label]}} [:params] ||= {} [:params].merge! :eid => eid, :embedded => true id = "as_#{eid}-embedded" = {:controller => remote_controller.to_s, :action => 'index'}.merge([:params]) content_tag(:div, :id => id, :class => 'active-scaffold-component') do url = url_for() # parse the ActiveRecord model name from the controller path, which # might be a namespaced controller (e.g., 'admin/admins') model = remote_controller.to_s.sub(/.*\//, '').singularize content_tag(:div, :class => 'active-scaffold-header') do content_tag :h2, link_to(args.first[:label] || active_scaffold_config_for(model).list.label, url, :remote => true) end << javascript_tag("jQuery('##{id}').load('#{url}');") end else = args.first if .is_a?(Hash) current_view = {:view => [:partial], :partial => true} if [:partial] current_view = {:view => [:template], :partial => false} if current_view.nil? && [:template] current_view[:locals] = [:locals] if !current_view.nil? && [:locals] view_stack << current_view if current_view.present? end result = render_without_active_scaffold(*args, &block) view_stack.pop if current_view.present? result end end |
#view_stack ⇒ Object
100 101 102 |
# File 'lib/active_scaffold/extensions/action_view_rendering.rb', line 100 def view_stack @_view_stack ||= [] end |