Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6689511
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:31:39+00:00 2026-05-26T05:31:39+00:00

I know that I shouldn’t be building a new associated image for my gallery

  • 0

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 %>

UPDATE #1: Adding the following methods inside the “controller do” block (based on the suggestion of Thomas Watson) worked for creating/editing Galleries.

def new
  @gallery = Gallery.new
  @new_image = @gallery.images.build
  new!
end

def edit
  @gallery = Gallery.find(params[:id])
  @new_image = @gallery.images.build
  edit!
end

def update
  @gallery = Gallery.find(params[:id])
  @new_image = @gallery.images.build
  update!
end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T05:31:40+00:00Added an answer on May 26, 2026 at 5:31 am

    Active Admin depends on Inherited Resources for its action magic. You can open up any controller action and add stuff to it. You can even create your own instance variable and Active Admin will automatically use that instead of creating its own.

    In your case you would do something like this if you where to build it on the new action:

    ActiveAdmin.register Gallery do
      controller do
        def new
          @gallery = Gallery.new
          @new_image = @gallery.images.build
    
          # call `new!` to ensure that the rest of the action continues as normal
          new!
        end
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know that such general questions shouldn't be asked, but can someone help me
Yes I know that it shouldn't be abused and that C# is primariy used
I know this shouldn't be that hard, but I couldn't find the answer on
So I know that you shouldn't use UrlWriter methods in a model, but I
I know that I shouldn't throw exceptions from a destructor. If my destructor calls
Disclaimer: I KNOW that in 99% of cases you shouldn't serialize data in a
I know that we shouldn't being using the registry to store Application Data anymore,
I know that you shouldn't rely on the values returned by InnoDB's SHOW TABLE
First of all, I know that you shouldn't try to use regex to modify
I know that I should put all the html elements in body tag, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.