Controllers inside the rails plugin folder is not loaded

18 views
Skip to first unread message

Srikanth Jeeva

unread,
Dec 7, 2011, 7:06:14 AM12/7/11
to bangal...@googlegroups.com
Hi,

In my rails(
2.3.5 ) application I have added a plugin named 'sample'.

I created controller in the path vendor/sample/app/controller/sample_controller.rb

class SampleController < ApplicationController
  def index
  end
end

I created routes for it in the path
vendor/sample/config/routes.rb

map.resources :sample

Now when i restart the server and hit http://localhost:3000/sample in the browser,

I get,

NameError in SampleController#index
uninitialized constant SampleController


I don't know why rails is not loading my SampleController inside the plugin by default. 
If rails did not load controllers by default, how to load the controllers
manually?



Thanks,
Srikanth

Punit Rathore

unread,
Dec 7, 2011, 7:21:30 AM12/7/11
to bangal...@googlegroups.com
You have to modify your config.load_paths in environment.rb file and add all the new paths you would like to add. Something like this -

config.load_paths += %W( #{RAILS_ROOT}/vendor/sample)

Cheers,
Punit Rathore
Runa Inc

Srikanth Jeeva

unread,
Dec 7, 2011, 7:56:48 AM12/7/11
to bangal...@googlegroups.com
Hi Punit,

Thanks for the reply. I did it and still the sample Issue. I wonder how it loads the routes from vendor/sample/config/routes.rb, but could not find controller.

Thanks,
Srikanth
 

Srikanth Jeeva

unread,
Dec 7, 2011, 7:59:02 AM12/7/11
to bangal...@googlegroups.com
sorry i meant still the same Issue

NameError in SampleController#index
uninitialized constant SampleController

Surya

unread,
Dec 7, 2011, 8:09:27 AM12/7/11
to bangal...@googlegroups.com
can you do "rake routes" and paste the result?
--

 Please consider the environment before printing this email.

Regards,
Surya

Punit Rathore

unread,
Dec 7, 2011, 8:11:28 AM12/7/11
to bangal...@googlegroups.com
I'm curious as to why you are trying to have a custom routes file, as opposed to using the default routes file provided by rails?

Punit Rathore
Runa Inc

hemant

unread,
Dec 7, 2011, 8:15:48 AM12/7/11
to bangal...@googlegroups.com
Couple of things:

1. You don't want to usually add anything in environment.rb to load something from plugin, if plugin wants to load some controller it must load itself.  Its been awhile since I have used rails2, but you can try:

in your plugin's init.rb:

$LOAD_PATH << File.join(File.dirname(__FILE__),"app")

and ensure that your controller is in, "app/controllers" directory of plugin.

also make sure that, each controller loaded via plugin is marked unloadable. 

2. vendor/sample/config/routes.rb is loaded because that is standard rails default.

cheers and let us know, if it works! (Don't have a rails 2 install to try, sorry).

 


--
Let them talk of their oriental summer climes of everlasting conservatories; give me the privilege of making my own summer with my own coals.

http://gnufied.org
http://twitter.com/gnufied

Srikanth Jeeva

unread,
Dec 7, 2011, 8:53:08 AM12/7/11
to bangal...@googlegroups.com
Hi Hemant,

thanks for the reply. I have added a init.rb file, added the line, made controller unloadable. But still no luck.

Actually when i create a new ror application with 2.3.5, without the init.rb file, the controllers are loaded from the plugin.

I'm working in old project and I wonder why controllers inside the plugins are not loaded!

Thanks,
Srikanth


Srikanth Jeeva

unread,
Dec 7, 2011, 9:00:08 AM12/7/11
to bangal...@googlegroups.com
I forgot to mention that its a Jruby on rails project. When i create a new jruby on rails app, controllers are loaded from plugin. So i dont think its a problem.
Reply all
Reply to author
Forward
0 new messages