I''m looking for ways to make my project file hierarchy look a bit neater, by joining what can be joined and removing what can be removed. I know now how to put controllers into subfolders (see my admin), but what about models? Here''s what I got so far: Rakefile app app/controllers app/controllers/about_controller.rb app/controllers/admin app/controllers/admin/ads_controller.rb app/controllers/admin/application_controller.rb app/controllers/admin/forums_controller.rb app/controllers/admin/moderatorships_controller.rb app/controllers/admin/sites_controller.rb app/controllers/admin/users_controller.rb app/controllers/ads_controller.rb app/controllers/application.rb app/controllers/forums_controller.rb app/controllers/main_controller.rb app/controllers/posts_controller.rb app/controllers/radio_controller.rb app/controllers/sessions_controller.rb app/controllers/sites_controller.rb app/controllers/topics_controller.rb app/controllers/users_controller.rb app/helpers app/helpers/about_helper.rb app/helpers/account_helper.rb app/helpers/ads_helper.rb app/helpers/application_helper.rb app/helpers/forums_helper.rb app/helpers/main_helper.rb app/helpers/moderatorships_helper.rb app/helpers/posts_helper.rb app/helpers/radio_helper.rb app/helpers/sessions_helper.rb app/helpers/sites_helper.rb app/helpers/topics_helper.rb app/helpers/users_helper.rb app/models app/models/ad.rb app/models/author.rb app/models/category.rb app/models/forum.rb app/models/mail.rb app/models/moderatorship.rb app/models/monitorship.rb app/models/parent_category.rb app/models/post.rb app/models/site.rb app/models/topic.rb app/models/user app/models/user.rb app/models/user/activation.rb app/models/user/editable.rb app/models/user/posting.rb app/models/user/states.rb app/models/user/validation.rb app/models/user_observer.rb app/views app/views/about app/views/about/main.html.erb app/views/about/privacy.html.erb app/views/about/safety.html.erb app/views/about/scams.html.erb app/views/about/terms.html.erb app/views/admin app/views/admin/ads app/views/admin/ads/categories.html.erb app/views/admin/ads/new_category.html.erb app/views/admin/ads/show.html.erb app/views/admin/forums app/views/admin/forums/_form.html.erb app/views/admin/forums/edit.html.erb app/views/admin/forums/new.html.erb app/views/admin/forums/show.html.erb app/views/admin/main app/views/admin/main/index.html.erb app/views/admin/sites app/views/admin/sites/_form.html.erb app/views/admin/sites/edit.html.erb app/views/admin/sites/new.html.erb app/views/admin/sites/show.html.erb app/views/admin/users app/views/admin/users/show.html.erb app/views/ads app/views/ads/_ad.html.erb app/views/ads/_category.html.erb app/views/ads/_form.html.erb app/views/ads/_form_header.html.erb app/views/ads/_parent.html.erb app/views/ads/_show_parent.html.erb app/views/ads/edit.html.erb app/views/ads/feed.atom.builder app/views/ads/feed.rss.builder app/views/ads/list.html.erb app/views/ads/manage.html.erb app/views/ads/new.html.erb app/views/ads/post.html.erb app/views/ads/select_category.rjs app/views/ads/show.html.erb app/views/ads/show_form.rjs app/views/forums app/views/forums/show.html.erb app/views/layouts app/views/layouts/_footer_1.html.erb app/views/layouts/_footer_2.html.erb app/views/layouts/_header_1.html.erb app/views/layouts/_header_2.html.erb app/views/layouts/application.html.erb app/views/mail app/views/mail/ad_activated.html.erb app/views/mail/ad_activation.html.erb app/views/mail/ad_forward.html.erb app/views/mail/forum_activated.html.erb app/views/mail/forum_activation.html.erb app/views/main app/views/main/index.html.erb app/views/posts app/views/posts/_edit.html.erb app/views/posts/edit.html.erb app/views/posts/index.html.erb app/views/radio app/views/radio/index.html.erb app/views/sessions app/views/sessions/new.rhtml app/views/sites app/views/sites/_form.html.erb app/views/sites/new.html.erb app/views/topics app/views/topics/_form.html.erb app/views/topics/edit.html.erb app/views/topics/new.html.erb app/views/topics/show.html.erb app/views/users app/views/users/_contact_info.html.erb app/views/users/_settings.html.erb app/views/users/edit.html.erb app/views/users/index.html.erb app/views/users/new.rhtml app/views/users/show.html.erb config config/boot.rb config/database.yml config/environment.rb config/environments config/environments/development.rb config/environments/production.rb config/initializers config/initializers/active_record.rb config/initializers/concerns.rb config/initializers/inflections.rb config/initializers/mime_types.rb config/routes.rb db db/migrate db/migrate/001_create_users.rb db/migrate/002_create_parent_categories.rb db/migrate/003_create_categories.rb db/migrate/004_create_ads.rb db/migrate/005_add_header_column_to_category_table.rb db/migrate/006_add_fields_to_ads_model.rb db/migrate/007_create_authors.rb db/migrate/008_create_permalinks.rb db/migrate/009_add_author_ip_and_author_ban_flag.rb db/schema.rb lib lib/authenticated_system.rb lib/authenticated_test_helper.rb lib/html_formatting.rb lib/tasks lib/tasks/load_fixtures.rake log log/development.log project.txt public public/404.html public/422.html public/500.html public/favicon.ico public/images public/images/logo.gif public/images/spinner.gif public/javascripts public/javascripts/application.js public/javascripts/controls.js public/javascripts/dragdrop.js public/javascripts/effects.js public/javascripts/lowpro.js public/javascripts/prototype.js public/javascripts/time.js public/robots.txt public/stylesheets public/stylesheets/display.css Any other suggestions to simplifying my app would be greatly appreciated. Kyrre --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
> I''m looking for ways to make my project file hierarchy look a bit > neater, by joining what can be joined and removing what can be > removed. I know now how to put controllers into subfolders (see my > admin), but what about models?I think you can add a sub directory to the load path, but I haven''t done it, so this is untested. Put this in environment.rb. config.load_paths += %W( #{RAILS_ROOT}/app/models/newdirectory ) Hope that helps. Cheers, Jordan --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
I have this line in my environments.rb file (within the initializer
block):
Dir.glob("#{RAILS_ROOT}/app/models/*[^(.rb|.ignore)]").each{|dir|
config.load_paths << dir }
So now I can organize models into subdirectories. And if there is a
subdir I don''t want loaded, I add ".ignore" to the end of it.
Works
like a charm for me.
-Danimal
--~--~---------~--~----~------------~-------~--~----~
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?hl=en
-~----------~----~----~----~------~----~------~--~---
KathysKode-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2008-Apr-23 00:40 UTC
Re: Can models be put in subfolders?
Danimal, Would you mind using a few simple words to describe what is going on with this (Dir.glob) you show below? What is the significance of Dir.glob and how is it used? Could you throw in some comments to show how this works? How is Dir.glob then used in your application? Thank you, Kathleen On Apr 22, 8:33 am, Danimal <fightonfightw...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I have this line in my environments.rb file (within the initializer > block): > > Dir.glob("#{RAILS_ROOT}/app/models/*[^(.rb|.ignore)]").each{|dir| > config.load_paths << dir } > > So now I can organize models into subdirectories. And if there is a > subdir I don''t want loaded, I add ".ignore" to the end of it. Works > like a charm for me. > > -Danimal--~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
http://ruby-doc.org/core/classes/Dir.html#M002347 Maybe will help. Lists all the filenames under the specified directory. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
That is truly awesome Danimal, much obliged! Kyrre On Apr 23, 8:47 am, Nathan Esquenazi <rails-mailing-l...@andreas- s.net> wrote:> http://ruby-doc.org/core/classes/Dir.html#M002347 > > Maybe will help. Lists all the filenames under the specified directory. > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
Kathleen,
There could possibly be a cleaner way of doing this... i.e. grabbing
only the directories. The reason I used Dir.glob is two-fold:
1) this was the example I found
2) I can create a directory called "maybetoss.ignore" and put model
files that I may be deleting but not sure.
It''s mostly just the way I work. As an application gets built out,
I''ll sometimes have models that I refactor or toss but I want to keep
the code around just in case.
So another way would be to use Dir.glob to get an array of everything
in app/models/ and then before adding it to the path, use
File.directory?(dir) to check if it''s a directory. The glob I have
just ignores ".rb" files.
So it''s really just a matter of how you want to arrange things in the
app/models/ directory. In my case, I only have .rb files, directories
and possibly a "something.ignore" directory, so that''s why I
use the
glob I did.
Perhaps a cleaner one would be:
Dir.glob("#{RAILS_ROOT}/app/models/*").each{|dir| config.load_paths
<< dir if File.directory?(dir) }
This will then just add all subdirs to the load path.
-Danimal
On Apr 22, 6:40 pm,
"KathysK...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org"
<KathysK...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> Danimal,
> Would you mind using a few simple words to describe what is going on
> with this (Dir.glob) you show below? What is the significance of
> Dir.glob and how is it used? Could you throw in some comments to show
> how this works?
> How is Dir.glob then used in your application?
> Thank you,
> Kathleen
>
> On Apr 22, 8:33 am, Danimal
<fightonfightw...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>
> > I have this line in my environments.rb file (within the initializer
> > block):
>
> >
Dir.glob("#{RAILS_ROOT}/app/models/*[^(.rb|.ignore)]").each{|dir|
> > config.load_paths << dir }
>
> > So now I can organize models into subdirectories. And if there is a
> > subdir I don''t want loaded, I add ".ignore" to the
end of it. Works
> > like a charm for me.
>
> > -Danimal
--~--~---------~--~----~------------~-------~--~----~
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?hl=en
-~----------~----~----~----~------~----~------~--~---
Here''s my little contribution this problem, this add recursively all
subfolders :
Rails::Initializer.run do |config|
##...
def add_all_models_subfolders_recursively(config, path)
Dir.glob(path).each do |dir|
if File.directory?(dir)
p dir
config.load_paths << dir
add_all_models_subfolders_recursively(config, "#{dir}/*")
end
end
end
add_all_models_subfolders_recursively(config, "#{RAILS_ROOT}/app/
models/*")
##...
end
++
--~--~---------~--~----~------------~-------~--~----~
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?hl=en
-~----------~----~----~----~------~----~------~--~---
Hi,
I like Danimal''s approach.
Mine is recusive:
Dir.glob("#{RAILS_ROOT}/app/models/**/*").each {|d| config.load_paths
<< d if File.directory?(d) }
Kind regards
Peter
--~--~---------~--~----~------------~-------~--~----~
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?hl=en
-~----------~----~----~----~------~----~------~--~---
Kabnot, That looks good to me... except that if I''m needing more than one level of subfolders for my models, then either I''m over-organizing or it is one big-ass project! The biggest Rails project I''ve done to date only needed about 5-6 subfolders in the models directory. But, each to their own. :-) -Danimal On Apr 25, 3:10 am, kabnot <kab...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Here''s my little contribution this problem, this add recursively all > subfolders : > > Rails::Initializer.run do |config| > ##... > def add_all_models_subfolders_recursively(config, path) > Dir.glob(path).each do |dir| > if File.directory?(dir) > p dir > config.load_paths << dir > add_all_models_subfolders_recursively(config, "#{dir}/*") > end > end > end > add_all_models_subfolders_recursively(config, "#{RAILS_ROOT}/app/ > models/*") > ##... > end > > ++--~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
Hey Danimals and Pater ! :) Finally I''ve choose Peter''s solution, witch is concise and beautifull. Mine is just strong-typing like and not in the ruby way :) Thanks. On Apr 25, 2:47 pm, Danimal <fightonfightw...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Kabnot, > > That looks good to me... except that if I''m needing more than one > level of subfolders for my models, then either I''m over-organizing or > it is one big-ass project! The biggest Rails project I''ve done to date > only needed about 5-6 subfolders in the models directory. But, each to > their own. :-) > > -Danimal > > On Apr 25, 3:10 am,kabnot<kab...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Here''s my little contribution this problem, this add recursively all > > subfolders : > > > Rails::Initializer.run do |config| > > ##... > > def add_all_models_subfolders_recursively(config, path) > > Dir.glob(path).each do |dir| > > if File.directory?(dir) > > p dir > > config.load_paths << dir > > add_all_models_subfolders_recursively(config, "#{dir}/*") > > end > > end > > end > > add_all_models_subfolders_recursively(config, "#{RAILS_ROOT}/app/ > > models/*") > > ##... > > end > > > ++--~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
Danimal wrote:> Kabnot, > > That looks good to me... except that if I''m needing more than one > level of subfolders for my models, then either I''m over-organizing or > it is one big-ass project! The biggest Rails project I''ve done to date > only needed about 5-6 subfolders in the models directory. But, each to > their own. :-) > > -DanimalFeels like, if you needed that many subfolders, you should probably have been namespacing your models. namely; Users::Facebook, Users::Web should live in /models/users but, if we add all subfolders, we lose the possibility of this. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---