I''m trying to split controller into several files. I tried extracting methods into separate files and then requiring them in main controller, but this doesn''t seem to work. controllers/reports/sales_reports.rb: class ReportController < ApplicationController def sales end end controllers/reports/purchases_reports.rb: class ReportController < ApplicationController def purchases end end controllers/report_controller.rb: require ''reports/sales_reports'' require ''reports/purchases_reports'' class ReportController < ApplicationController end This doesn''t seem to work. What I''m doing wrong? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Warning: I''m a TOTAL Ruby/Rails beginner -------------- you would have to extract the shared methods into modules, not classes (controllers) and then require AND include them. - require loads the files into the class file - include mixes the loaded file''s methods into the class Put the modules in /lib directory for the example below. you can also put them in a subdir of the controller dir and give the path in the require call sales.rb: module sales def sales .... end purchases.rb: module purchases def purchases ... end end controllers/report_controller.rb: require ''sales'' require ''reports'' class ReportController < ApplicationController include sales include purchases ...class code ... end The methods "sales" & "purchases" will then be available in the ReportController class Check out Modules Doc for a more detailed explanation like avoiding namespace problems etc.: http://www.ruby-doc.org/docs/ProgrammingRuby/ my code is most probably wrong in some details, as i said above i''m a total beginner and the whole syntax stuff is still in the learning-by-doing process --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Thank you, as always the solution was to read ''Programming Ruby'' :) You suggestion worked, the only error was that module names have to start with capital letter. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---