I have a Rails 2 project in which models are in sub-folders, but not in
a name space

app/models/sub_folder/posts.rb

class Post < ActiveRecord::Base
end

The controllers are also in sub-folders, but are name spaced (views also
in a corresponding sub_folder).

app/controllers/sub_folder/posts_controller.rb

class SubFolder::PostsController < ApplicationController
end

This works fine, but I want to move on to Rails 3, and it all falls
apart...

In application.rb I have

config.autoload_paths += Dir["#{config.root}/app/models/**/"]

So Rails should be able to find the models. However running tests (which
are subfoldered in an analogous way), I get

LoadError: Expected R:/test3/app/models/sub_folder/post.rb to define
SubFolder::Post

So okay, suppose I name-space my models? Now I get:

LoadError: Expected R:/test3/app/models/sub_folder/post.rb to define
Post

Taking the model out of it sub-folder does allow the tests to pass, but
my real project has over 30 models, and I really do want them to be
structured somehow.

Running on Rails version 3.2.2, with Ruby 1.9.2, on JRuby 1.6.7 by the
way, and all the above are from a simple test project that I created
just for this purpose; no custom code except as noted above. I have
found several web pages about this issue, but they just indicate the
config.autoload_paths bit should solve the problem; am I missing
something simple here?

--
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@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Search Discussions

  • Beena Shetty at Mar 28, 2012 at 9:18 am
    Hi,
    In model i.e app/models/sub_folder/posts.rb you need to specify
    sub_folder namespace to it then it will work.

    Eg:-
    class SubFolder::Post < ActiveRecord::Base
    end

    whenever u fire any query you need to specify
    SubFolder::Post.all

    Then only it will work .

    --
    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@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedMar 26, '12 at 9:04a
activeMar 28, '12 at 9:18a
posts2
users1
websiterubyonrails.org
irc#RubyOnRails

1 user in discussion

Beena Shetty: 2 posts

People

Translate

site design / logo © 2021 Grokbase