Code Monkey home page Code Monkey logo

Comments (4)

ryancheung avatar ryancheung commented on July 17, 2024

I manually added the help to the controller and then the issue is gone.

from activeadmin-axlsx.

baxang avatar baxang commented on July 17, 2024

I have a looking similar issue here.

After defining gem 'activeadmin-axlsx' in Gemfile, my Rails application's controllers can't use custom helpers which previously worked well. I tried helper :all in ApplicationController that all other controllers inherit, it didn't work and I had to specify helpers I needed one by one.

I don't know much about how helpers are included, but it looks that activeadmin-axlsx gem affects the mechanism.

Maybe re-open this issue?

from activeadmin-axlsx.

SteveLTN avatar SteveLTN commented on July 17, 2024

I have also met this problem, and I tried to solve it, but unfortunately I failed.

So here's what I have done:

First, I cloned this gem into my local filesystem, and used my local version of this gem in my Gemfile. Since I don't really understand what's happening here, I started to comment out lines, in order to locate the problematic line of code.

So, I've found it is this line that causes the problem:
Once I commented this line out, my helpers are automatically loaded (Though this gem did not work, I suppose).

Since it mixes a module into ActiveAdmin::ResourceController, I dug into this line, which lead me to resource_controller_extension.rb, and I commented these lines out, which made ActiveAdmin::Axlsx::ResourceControllerExtension an empty module. But my helpers are still not loaded!

In order to make sure that nothing in somewhere else magically adds stuff into the module, I changed the file into this:

# require 'active_admin'
# require 'active_admin/axlsx/version'
# require 'active_admin/axlsx/builder'
# require 'active_admin/axlsx/dsl'
# require 'active_admin/axlsx/resource_extension'
require 'active_admin/axlsx/resource_controller_extension'

class Railtie < ::Rails::Railtie
  config.before_initialize do
    # begin
    #   if Mime::Type.lookup_by_extension(:xlsx).nil?
    #     # The mime type to be used in respond_to |format| style web-services in rails
    #     Mime::Type.register "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", :xlsx
    #   end
    # rescue NameError
    #   # noop
    # end

    # ActiveAdmin::ResourceDSL.send :include, ActiveAdmin::Axlsx::DSL
    # ActiveAdmin::Resource.send :include, ActiveAdmin::Axlsx::ResourceExtension

    # Problematic Line
    # ActiveAdmin::ResourceController.send :include, ActiveAdmin::Axlsx::ResourceControllerExtension
    module Foobar
    end

    ActiveAdmin::ResourceController.send :include, Foobar

    # ActiveAdmin::Views::PaginatedCollection.add_format :xlsx
  end
end

and it will still prevent my helpers from auto-loading! Once I comment ActiveAdmin::ResourceController.send :include, Foobar out, my helpers would just be back, magically.

I tried to mix an empty module in in an initializer in my Rails application, it won't affect anything.

The rest of this problem is beyond my knowledge, does anyone have any ideas?

from activeadmin-axlsx.

SteveLTN avatar SteveLTN commented on July 17, 2024

Fixed it in this pull-request.

from activeadmin-axlsx.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.