gregbell/active_admin — Issue #636: Want to build new association in controller instead of view partial
Author: bdastous
Created: 2011-10-17 16:37:24+00:00
State: open

I know that I shouldn't be building a new associated image for my gallery in the Gallery view partial. However, I can't figure out to do this in ActiveAdmin's generated controller, which can apparently be customized using the "Controller" method in the resource file. How can I do this using the Controller method instead of the view partial?

Here is my Gallery resource file:

ActiveAdmin.register Gallery do

controller.authorize_resource

scope_to :current_admin_user

before_filter :block_access

controller do
def block_access
if params && params['q'] && params['q']['admin_user_id_eq']
params['q']['admin_user_id_eq'] = nil
end
end
end

form :partial => "form"

end

Here is my Gallery view partial:

<% new_image = @gallery.images.build %>
<%= semantic_form_for [:admin, @gallery] do |g| %>
<%= g.inputs "Details" do %>
<%= g.input :title %>
<%= g.input :images, :as => :check_boxes, :label_method => Proc.new { |image| image_tag(image.thumb_path, :alt => "") + content_tag("h3", image.title) } %>
<% end %>
<%= g.inputs :for => [:images, new_image], :name => "New Image" do |image| %>
<% if image.object.new_record? %>
<%= image.input :title %>
<%= image.input :asset, :as => :file %>
<% end %>
<% end %>
<%= g.buttons %>
<% end %>