We have decided to wrap each of our model classes in a module, where the module name is currently the same across all models and is the name of the application. So, for example, we have: module SpringBase class User < ActiveRecord::Base ... end end My reading suggests that I should site all model files in the directory app/models/spring_base/ to, I hope, help Rails to find them when I have code such as user=SpringBase::User.new in my controller logic. Is this the correct approach? Thanks.
Lee wrote:> We have decided to wrap each of our model classes in a module, where > the module name is currently the same across all models and is the > name of the application.[...] Why? Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/.
We want to namespace our code to avoid conflicts with any framework code. For example, we had a method called ''changed'' in our models which clashed with an ActiveRecord-based rmethod of the same name and this led to many hours of debugging. My research suggests it is valid to namespace models and that one should use the same approach as for namespacing controllers. On 22 June, 20:57, Marnen Laibow-Koser <rails-mailing-l...@andreas- s.net> wrote:> Leewrote: > > We have decided to wrap each of our model classes in a module, where > > the module name is currently the same across allmodelsand is the > > name of the application. > > [...] > > Why? > > Best, > -- > Marnen Laibow-Koserhttp://www.marnen.org > mar...-sbuyVjPbboAdnm+yROfE0A@public.gmane.org > -- > Posted viahttp://www.ruby-forum.com/.
Lee wrote:> We want to namespace our code to avoid conflicts with any framework > code.I don''t see how this will help. Each model is *already* its own namespace, so further namespacing them won''t make a difference in this regard.> For example, we had a method called ''changed'' in our models > which clashed with an ActiveRecord-based rmethod of the same name and > this led to many hours of debugging.It will still clash, because your models will still inherit from ActiveRecord::Base.> > My research suggests it is valid to namespace models and that one > should use the same approach as for namespacing controllers.I''ve never tried doing this, but I suspect that you''re going about it backwards. You''re trying to include the model in the module, which will not break up the model''s namespace; what you may need to do is include the module into the model instead. However, I think I would advise against this. If your model methods are conflicting with framework methods, it''s probably better to rename them -- it will be less confusing. Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/.
Hi, I am trying to namespace my models in a Rails app. I put this in routes map.namespace(:property) do |property| property.root :controller => :venues, :active_scaffold => true property.resources :location_groups, :active_scaffold => true end and this in app/controllers/property/venues_controller module Property class VenuesController < ApplicationController active_scaffold Venue end end this in app/modesl/property/venue module Property class Venue < ActiveRecord::Base has_many :location_groups end end this for app/controllers/property/location_groups_controller module Property class LocationGroupsController < ApplicationController active_scaffold LocationGroup end end and this for app/modesl/property/location_group module Property class LocationGroup < ActiveRecord::Base belongs_to :venue end end now if I try to load http://localhost:3000/property/location_groups/new I get ActionView::TemplateError (Could not find Property::Property::VenuesController or Property::Property::VenueController) I am confused as to how to do this correctly... any ideas? Am I correct to do this? I don''t want all my models in one folder... I want to "package" them.