Skip to content

Instantly share code, notes, and snippets.

@clyfe
Created March 1, 2011 22:44
Show Gist options
  • Save clyfe/850052 to your computer and use it in GitHub Desktop.
Save clyfe/850052 to your computer and use it in GitHub Desktop.
Never finished work on AS cancan bridge record autowiring
<table cellpadding="0" cellspacing="0">
<%
begin
remote_controller = active_scaffold_controller_for(column.association.klass).new
remote_request_env = {}
request.env.select {|key, value| key == key.upcase || key == 'rack.input'}.each {|item| remote_request_env[item[0]] = item[1]}
remote_request_env["warden"] = request.env["warden"] if (request.env.has_key?("warden"))
remote_request = ActionDispatch::Request.new(remote_request_env)
remote_request.session = session
remote_controller.instance_variable_set(:@_request, remote_request) # provide the session for nesting purposes
@record = remote_controller.send(:new_model)
p @record
rescue ActiveScaffold::ControllerNotFound
@record = column.association.klass.new
end
-%>
<%= render :partial => 'horizontal_subform_header', :locals => {:parent_record => parent_record} %>
<tbody id="<%= sub_form_list_id(:association => column.name) %>">
<% associated.each_index do |index| %>
<% @record = associated[index] -%>
<% if @record.errors.count -%>
<tr class="association-record-errors">
<td colspan="<%= active_scaffold_config_for(@record.class).subform.columns.length + 1 %>" id="<%= element_messages_id :action => @record.class.name.underscore, :id => "#{parent_record.id}-#{index}" %>">
<%= active_scaffold_error_messages_for :record, :object_name => @record.class.model_name.human.downcase %>
</td>
</tr>
<% end %>
<%= render :partial => 'horizontal_subform_record', :locals => {:scope => column_scope(column), :parent_record => parent_record, :column => column, :locked => @record.new_record? && @record == associated.last} %>
<% end -%>
</tbody>
</table>
<%= render :partial => 'form_association_footer', :locals => {:parent_record => parent_record, :column => column, :associated => associated} -%>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment