I'm trying to pass a variable from my controller to a custom activeadmin page but I can't seem to figure it out.
I basically have a form that uploads a file and it parses it. If it reaches an error, it throws one and redirects to the custom page.
class ToolController < ApiController
def import
begin
Schedule.Parse(data)
rescue MissingDependencyError => e
@dependencies = "test"
redirect_to admin_import_path({}.merge(flash_error: "Missing Dependencies", dependency_error: true, :locals => { :m => e.object }))
end
end
class MissingDependencyError < StandardError
attr_reader :object
def initialize(object)
@object = object
end
end
ActiveAdmin.register_page "Import" do |lab|
menu false
content do
@dependencies
end
end
@dependencies comes back as nil -> why?
I can pass it through the params hash but that's not the right way.
Instance variables are not available after a
redirect_to... theredirect_tocreates a new controller instance and all the instance variables of the previous controller object are gone.Instead of the params hash, you can use the sessions hash
and