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

  • Home
  • SEARCH
  • 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 8535173
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T10:22:18+00:00 2026-06-11T10:22:18+00:00

I am trying to add a mixin to my controller dynamically depending on the

  • 0

I am trying to add a mixin to my controller dynamically depending on the request parameters like so :

# Controller
class QuantitiesController < Admin::BaseController
  before_filter :extend_input_method, only: [:create, :new]
  def extend_input_method
    input_method = params[:input_method]
    if input_method
      send(:extend, "InputMethod::#{input_method.classify}".constantize)
    end
  end
end

# Mixin that gets included in the controller
module InputMethod::Single
  include InputMethod::Helpers

  def new
    puts "CALLED #new" # Debug information
    load_recent_entries
    quantity
  end

  def create
    @quantity = scoped_by_subject.new(process_attributes)

    if @quantity.save
      save_success
    else
      load_recent_entries
      save_error
    end
  end
end

The new method never gets called but my template gets rendered without raising an exception, even if action_name is new and respond_to?("new") is true after extending the instance.

I’d like to understand why this isn’t working and how I can achieve something similar.

  • 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-06-11T10:22:19+00:00Added an answer on June 11, 2026 at 10:22 am

    This is the solution I came up with. It works for my needs.

    class QuantitiesController < Admin::BaseController
      before_filter :extend_input_method, only: [:create, :new]
    
      def new
        _new
      end
    
      def create
        _create
      end
    
      private
      def extend_input_method
        input_method = params[:input_method]
        extend(Dep.get("InputMethod::#{input_method.classify}")) if input_method
      end
    
    end
    
    
    module InputMethod::Single
      include InputMethod::Helpers
    
      def _new
        # Do stuff...
      end
    
      def _create
        # Do stuff...
      end
    
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying add picture boxes dynamically. My code is as PictureBox picture =
Im new to asp.net mvc. I'm trying add new model class but it got
Trying to add a class object into a List using reflection, but when invoking
Trying to add a dynamic class value to one of my columns in CGridView:
I'm trying to write a @mixin for High Density Display like the iPhone 4+
im trying to add a css class in my javascript code but when i
Trying to add a class to a button if there has been any input
I am trying add items to CellRendererCombo dynamically. See the code below. When I
I am trying to define simple getter/setter methods for a mixin class that I
i'm new to django and im trying add a user using django admin page.

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.