ChiliProject is not maintained anymore. Please be advised that there will be no more updates.

We do not recommend that you setup new ChiliProject instances and we urge all existing users to migrate their data to a maintained system, e.g. Redmine. We will provide a migration script later. In the meantime, you can use the instructions by Christian Daehn.

need to wrap a existing controller method

Added by Arnauld NYAKU at 2011-12-07 04:46 pm

I try this .

 1module UserLandingPageWelcomeControllerPatch
 2  def self.included(base) # :nodoc:
 3    base.send(:include, InstanceMethods)
 4
 5    base.class_eval do
 6      unloadable
 7      alias_method_chain :index, :redirect
 8    end
 9  end
10end
11
12module InstanceMethods
13    # Adds a rates tab to the user administration page
14    def index_with_redirect
15       redirect_to 'http://mine.local/projects/arnauld-test-1/wiki'
16    end
17end
18
19WelcomeController.send(:include, UserLandingPageWelcomeControllerPatch)

and i get error below

#     File     Line     Location
0     /home/arnauld.nyaku/.rvm/gems/ruby-1.8.7-p352@mine/gems/activesupport-2.3.14/lib/active_support/dependencies.rb     466     in `load_missing_constant'
1     /home/arnauld.nyaku/.rvm/gems/ruby-1.8.7-p352@mine/gems/activesupport-2.3.14/lib/active_support/dependencies.rb     106     in `const_missing'
2     /home/arnauld.nyaku/Applications/mine/app/helpers/application_helper.rb     21     
3     /home/arnauld.nyaku/.rvm/gems/ruby-1.8.7-p352@mine/gems/activesupport-2.3.14/lib/active_support/dependencies.rb     184     in `require'
4     /home/arnauld.nyaku/.rvm/gems/ruby-1.8.7-p352@mine/gems/activesupport-2.3.14/lib/active_support/dependencies.rb     184     in `require'
5     /home/arnauld.nyaku/.rvm/gems/ruby-1.8.7-p352@mine/gems/activesupport-2.3.14/lib/active_support/dependencies.rb     291     in `require_or_load'
6     /home/arnauld.nyaku/.rvm/gems/ruby-1.8.7-p352@mine/gems/activesupport-2.3.14/lib/active_support/dependencies.rb     250     in `depend_on'
7     /home/arnauld.nyaku/.rvm/gems/ruby-1.8.7-p352@mine/gems/activesupport-2.3.14/lib/active_support/dependencies.rb     162     in `require_dependency'
8     /home/arnauld.nyaku/.rvm/gems/ruby-1.8.7-p352@mine/gems/actionpack-2.3.14/lib/action_controller/helpers.rb     197     in `default_helper_module!'
9     /home/arnauld.nyaku/.rvm/gems/ruby-1.8.7-p352@mine/gems/actionpack-2.3.14/lib/action_controller/helpers.rb     212     in `__send__'
10     /home/arnauld.nyaku/.rvm/gems/ruby-1.8.7-p352@mine/gems/actionpack-2.3.14/lib/action_controller/helpers.rb     212     in `inherited'
11     /home/arnauld.nyaku/Applications/mine/app/controllers/application_controller.rb     18     
12     /home/arnauld.nyaku/.rvm/gems/ruby-1.8.7-p352@mine/gems/activesupport-2.3.14/lib/active_support/dependencies.rb     184     in `require'
13     /home/arnauld.nyaku/.rvm/gems/ruby-1.8.7-p352@mine/gems/activesupport-2.3.14/lib/active_support/dependencies.rb     184     in `require'
14     /home/arnauld.nyaku/.rvm/gems/ruby-1.8.7-p352@mine/gems/activesupport-2.3.14/lib/active_support/dependencies.rb     291     in `require_or_load'
15     /home/arnauld.nyaku/.rvm/gems/ruby-1.8.7-p352@mine/gems/activesupport-2.3.14/lib/active_support/dependencies.rb     451     in `load_missing_constant'
16     /home/arnauld.nyaku/.rvm/gems/ruby-1.8.7-p352@mine/gems/activesupport-2.3.14/lib/active_support/dependencies.rb     106     in `const_missing'
17     /home/arnauld.nyaku/.rvm/gems/ruby-1.8.7-p352@mine/gems/activesupport-2.3.14/lib/active_support/dependencies.rb     118     in `const_missing'
18     /home/arnauld.nyaku/Applications/mine/app/controllers/welcome_controller.rb     15     
19     /home/arnauld.nyaku/.rvm/gems/ruby-1.8.7-p352@mine/gems/activesupport-2.3.14/lib/active_support/dependencies.rb     184     in `require'
20     /home/arnauld.nyaku/.rvm/gems/ruby-1.8.7-p352@mine/gems/activesupport-2.3.14/lib/active_support/dependencies.rb     184     in `require'
21     /home/arnauld.nyaku/.rvm/gems/ruby-1.8.7-p352@mine/gems/activesupport-2.3.14/lib/active_support/dependencies.rb     291     in `require_or_load'
22     /home/arnauld.nyaku/.rvm/gems/ruby-1.8.7-p352@mine/gems/activesupport-2.3.14/lib/active_support/dependencies.rb     451     in `load_missing_constant'
23     /home/arnauld.nyaku/.rvm/gems/ruby-1.8.7-p352@mine/gems/activesupport-2.3.14/lib/active_support/dependencies.rb     106     in `const_missing'
24     /home/arnauld.nyaku/.rvm/gems/ruby-1.8.7-p352@mine/gems/activesupport-2.3.14/lib/active_support/dependencies.rb     118     in `const_missing'
25     /home/arnauld.nyaku/Applications/mine/vendor/plugins/chiliproject_user_landing_page/lib/user_landing_page_welcome_controller_patch.rb     23     
26     /home/arnauld.nyaku/.rvm/gems/ruby-1.8.7-p352@mine/gems/activesupport-2.3.14/lib/active_support/dependencies.rb     184     in `require'
27     /home/arnauld.nyaku/.rvm/gems/ruby-1.8.7-p352@mine/gems/activesupport-2.3.14/lib/active_support/dependencies.rb     184     in `require'
28     /home/arnauld.nyaku/Applications/mine/vendor/plugins/chiliproject_user_landing_page/init.rb     9     in `evaluate_init_rb'
29     /home/arnauld.nyaku/Applications/mine/vendor/plugins/chiliproject_user_landing_page/init.rb     7     in `foreach'
30     /home/arnauld.nyaku/Applications/mine/vendor/plugins/chiliproject_user_landing_page/init.rb     7     in `evaluate_init_rb'
31     /home/arnauld.nyaku/.rvm/gems/ruby-1.8.7-p352@mine/gems/rails-2.3.14/lib/rails/plugin.rb     158     in `evaluate_init_rb'
32     /home/arnauld.nyaku/.rvm/gems/ruby-1.8.7-p352@mine/gems/activesupport-2.3.14/lib/active_support/core_ext/kernel/reporting.rb     11     in `silence_warnings'
33     /home/arnauld.nyaku/.rvm/gems/ruby-1.8.7-p352@mine/gems/rails-2.3.14/lib/rails/plugin.rb     154     in `evaluate_init_rb'
34     /home/arnauld.nyaku/.rvm/gems/ruby-1.8.7-p352@mine/gems/rails-2.3.14/lib/rails/plugin.rb     48     in `load'
35     /home/arnauld.nyaku/Applications/mine/config/../vendor/plugins/engines/lib/engines/plugin.rb     45     in `load'
36     /home/arnauld.nyaku/.rvm/gems/ruby-1.8.7-p352@mine/gems/rails-2.3.14/lib/rails/plugin/loader.rb     38     in `load_plugins'
37     /home/arnauld.nyaku/.rvm/gems/ruby-1.8.7-p352@mine/gems/rails-2.3.14/lib/rails/plugin/loader.rb     37     in `each'
38     /home/arnauld.nyaku/.rvm/gems/ruby-1.8.7-p352@mine/gems/rails-2.3.14/lib/rails/plugin/loader.rb     37     in `load_plugins'
39     /home/arnauld.nyaku/.rvm/gems/ruby-1.8.7-p352@mine/gems/rails-2.3.14/lib/initializer.rb     369     in `load_plugins'
40     /home/arnauld.nyaku/.rvm/gems/ruby-1.8.7-p352@mine/gems/rails-2.3.14/lib/initializer.rb     165     in `process'
41     /home/arnauld.nyaku/.rvm/gems/ruby-1.8.7-p352@mine/gems/rails-2.3.14/lib/initializer.rb     113     in `send'
42     /home/arnauld.nyaku/.rvm/gems/ruby-1.8.7-p352@mine/gems/rails-2.3.14/lib/initializer.rb     113     in `run'
43     /home/arnauld.nyaku/Applications/mine/config/environment.rb     39     
44     /home/arnauld.nyaku/.rvm/gems/ruby-1.8.7-p352/gems/passenger-3.0.9/lib/phusion_passenger/classic_rails/application_spawner.rb     222     in `require'
45     /home/arnauld.nyaku/.rvm/gems/ruby-1.8.7-p352/gems/passenger-3.0.9/lib/phusion_passenger/classic_rails/application_spawner.rb     222     in `preload_application'
46     /home/arnauld.nyaku/.rvm/gems/ruby-1.8.7-p352/gems/passenger-3.0.9/lib/phusion_passenger/classic_rails/application_spawner.rb     181     in `initialize_server'
47     /home/arnauld.nyaku/.rvm/gems/ruby-1.8.7-p352/gems/passenger-3.0.9/lib/phusion_passenger/utils.rb     572     in `report_app_init_status'
48     /home/arnauld.nyaku/.rvm/gems/ruby-1.8.7-p352/gems/passenger-3.0.9/lib/phusion_passenger/classic_rails/application_spawner.rb     174     in `initialize_server'
49     /home/arnauld.nyaku/.rvm/gems/ruby-1.8.7-p352/gems/passenger-3.0.9/lib/phusion_passenger/abstract_server.rb     204     in `start_synchronously'
50     /home/arnauld.nyaku/.rvm/gems/ruby-1.8.7-p352/gems/passenger-3.0.9/lib/phusion_passenger/abstract_server.rb     180     in `start'
51     /home/arnauld.nyaku/.rvm/gems/ruby-1.8.7-p352/gems/passenger-3.0.9/lib/phusion_passenger/classic_rails/application_spawner.rb     149     in `start'
52     /home/arnauld.nyaku/.rvm/gems/ruby-1.8.7-p352/gems/passenger-3.0.9/lib/phusion_passenger/spawn_manager.rb     219     in `spawn_rails_application'
53     /home/arnauld.nyaku/.rvm/gems/ruby-1.8.7-p352/gems/passenger-3.0.9/lib/phusion_passenger/abstract_server_collection.rb     132     in `lookup_or_add'
54     /home/arnauld.nyaku/.rvm/gems/ruby-1.8.7-p352/gems/passenger-3.0.9/lib/phusion_passenger/spawn_manager.rb     214     in `spawn_rails_application'
55     /home/arnauld.nyaku/.rvm/gems/ruby-1.8.7-p352/gems/passenger-3.0.9/lib/phusion_passenger/abstract_server_collection.rb     82     in `synchronize'
56     /home/arnauld.nyaku/.rvm/gems/ruby-1.8.7-p352/gems/passenger-3.0.9/lib/phusion_passenger/abstract_server_collection.rb     79     in `synchronize'
57     /home/arnauld.nyaku/.rvm/gems/ruby-1.8.7-p352/gems/passenger-3.0.9/lib/phusion_passenger/spawn_manager.rb     213     in `spawn_rails_application'
58     /home/arnauld.nyaku/.rvm/gems/ruby-1.8.7-p352/gems/passenger-3.0.9/lib/phusion_passenger/spawn_manager.rb     132     in `spawn_application'
59     /home/arnauld.nyaku/.rvm/gems/ruby-1.8.7-p352/gems/passenger-3.0.9/lib/phusion_passenger/spawn_manager.rb     275     in `handle_spawn_application'
60     /home/arnauld.nyaku/.rvm/gems/ruby-1.8.7-p352/gems/passenger-3.0.9/lib/phusion_passenger/abstract_server.rb     357     in `__send__'
61     /home/arnauld.nyaku/.rvm/gems/ruby-1.8.7-p352/gems/passenger-3.0.9/lib/phusion_passenger/abstract_server.rb     357     in `server_main_loop'
62     /home/arnauld.nyaku/.rvm/gems/ruby-1.8.7-p352/gems/passenger-3.0.9/lib/phusion_passenger/abstract_server.rb     206     in `start_synchronously'
63     /home/arnauld.nyaku/.rvm/gems/ruby-1.8.7-p352/gems/passenger-3.0.9/helper-scripts/passenger-spawn-server     99     

Anyone has any clue about this?
Thks


Replies (2)

RE: need to wrap a existing controller method - Added by Felix Schäfer at 2011-12-07 06:21 pm

The InstanceMethod module must be define in the same module in which you define self.included, something like that:

 1module UserLandingPageWelcomeControllerPatch
 2  def self.included(base) # :nodoc:
 3    base.send(:include, InstanceMethods)
 4
 5    base.class_eval do
 6      unloadable
 7      alias_method_chain :index, :redirect
 8    end
 9  end
10
11  module InstanceMethods
12    # Adds a rates tab to the user administration page
13    def index_with_redirect
14      redirect_to 'http://mine.local/projects/arnauld-test-1/wiki'
15    end
16  end
17end
18
19WelcomeController.send(:include, UserLandingPageWelcomeControllerPatch)

(I haven't tried it though, so there might be other problems…)

RE: need to wrap an existing controller method - Added by Arnauld NYAKU at 2011-12-07 11:05 pm

Thk Felix Schäfer.
I fixed the error.

module WelcomeControllerPatch
def self.included(base) # :nodoc:
base.send(:include, InstanceMethods)
base.class_eval do
unloadable
alias_method_chain :index, :redirect
end
end
module InstanceMethods
def index_with_redirect
redirect_to a_url
end
end
end
require 'dispatcher'
Dispatcher.to_prepare do
WelcomeController.send(:include, WelcomeControllerPatch)
end

(1-2/2)