Ruby on Rails中的控制器是否存在任何部分内容

Sal*_*lil 2 ruby ruby-on-rails controllers partial

我有一个控制器有超过1000行代码.

对了,我没有为这个控制器做代码审查.我根据模块安排我的方法.现在我意识到我的控制器不易维护,所以我想要跟随它

class UsersController < ApplicationController  
  #Code to require files here 
  #before filter code will goes here 

  #############Here i want to call that partial like things. following is just pseudo #########
    history module
    account module
    calendar module
    shipment module
    payment module
 ####################################################################

end #end of class
Run Code Online (Sandbox Code Playgroud)

这有助于我维护代码,因为当我更改历史模块时,我确信我的帐户模块未更改.我知道CVS但我更喜欢每个模块的50个副本而不是200个我的users_controller.rb本身.

PS: - 我想肯定答案.请不要回答,你应该为不同的模块使用不同的控制器...... bla ... bla ... bla ...因为我不可能这样做.

编辑: - 我的版本是

rails -v
  Rails 2.3.4
ruby -v
  ruby 1.8.6 (2008-08-11 patchlevel 287) [i386-linux]
Run Code Online (Sandbox Code Playgroud)

Chr*_*ris 5

这应该适合你:

app/controllers/some_controller.rb

class SomeController < ApplicationController
  include MyCustomMethods
end
Run Code Online (Sandbox Code Playgroud)

lib/my_custom_methods.rb

module MyCustomMethods
  def custom
    render :text => "Rendered from a method included from a module!"
  end
end
Run Code Online (Sandbox Code Playgroud)

config/routes.rb

# For rails 3:
match '/cool' => "some#custom"

# For rails 2:
map.cool 'cool', :controller => "some", :action => "custom"
Run Code Online (Sandbox Code Playgroud)

启动你的应用程序并点击http:// localhost:3000/cool,你将从模块中获得自定义方法.