Forum: Rails Engines Routing problem

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
71c85a662af0764df3a77cc00db166c9?d=identicon&s=25 Raphael Bauduin (Guest)
on 2008-10-30 10:33
(Received via mailing list)
Hi,

I'm developing an engine with a controller, and I have problems to
configure the routing.
The engine is located in vendor/plugins/web_file_attachment. Under
that directory:
- the controller is in app/controllers/web_file_attachments.rb
- I'm trying  with this controller classes:
  class WebFileAttachment::WebFileAttachmentsController <
ApplicationController
  and I have tried with equivalent configurations for class
WebFileAttachmentsController < ApplicationController

- in routes.rb, I have this (following the docs stating that the
plugin name is the first part of the controller name):
  connect "/app/web_file_attachments/:action/:id", :controller =>
"web_file_attachment/web_file_attachments"

 And in the main rails config/routes.rb I have this:
  map.from_plugin :web_file_attachment

I still end with this error:
   uninitialized constant
WebFileAttachment::WebFileAttachmentsController

though this is exactly how I name my controller.
If I try
  require 'web_file_attachments'
in init.rb, I get an error with ApplicationController not defined.

What am I doing wrong here?
I'm using rails 2.1.1 and engines 2.0.0

Thanks in advance.

Raphaƫl
Acd62030df551952268e84c8fff26a5b?d=identicon&s=25 James Adam (Guest)
on 2008-10-30 10:50
(Received via mailing list)
On 30 Oct 2008, at 09:33, Raphael Bauduin wrote:

>  and I have tried with equivalent configurations for class
> I still end with this error:
>   uninitialized constant
> WebFileAttachment::WebFileAttachmentsController
>
> though this is exactly how I name my controller.
> If I try
>  require 'web_file_attachments'
> in init.rb, I get an error with ApplicationController not defined.
>
> What am I doing wrong here?
> I'm using rails 2.1.1 and engines 2.0.0

The most obvious things are:

  * if your controller is
WebFileAttachment::WebFileAttachmentsController, then it should be in
a file called vendor/plugins/web_file_attachment/app/controllers/
web_file_attachment/web_file_attachments_controller.rb
  * if your controller is WebFileAttachmentsController, then it should
be in a file called vendor/plugins/web_file_attachment/app/controllers/
web_file_attachments_controller.rb

Essentially - the name of the plugin isn't involved in namespacing the
controller, and the file needs to end with _controller.rb. Hopefully
that should get you back on track.

Thanks,

James
71c85a662af0764df3a77cc00db166c9?d=identicon&s=25 Raphael Bauduin (Guest)
on 2008-10-30 12:15
(Received via mailing list)
On Thu, Oct 30, 2008 at 10:50 AM, James Adam <james@lazyatom.com> wrote:
>>  class WebFileAttachment::WebFileAttachmentsController <
>>  map.from_plugin :web_file_attachment
>> I'm using rails 2.1.1 and engines 2.0.0
>
> The most obvious things are:
>
>  * if your controller is WebFileAttachment::WebFileAttachmentsController,
> then it should be in a file called
> 
vendor/plugins/web_file_attachment/app/controllers/web_file_attachment/web_file_attachments_controller.rb

Maybe the documentation could be a bit clearer? The example at
http://api.rails-engines.org/classes/Engines/Rails...
puts 'my_pluign/' in the controller route.

>  * if your controller is WebFileAttachmentsController, then it should be in
> a file called
> vendor/plugins/web_file_attachment/app/controllers/web_file_attachments_controller.rb

yes, you're right, I misnamed the controller file. Thanks for pointing
it out!

Raph
Acd62030df551952268e84c8fff26a5b?d=identicon&s=25 James Adam (Guest)
on 2008-10-30 12:24
(Received via mailing list)
On 30 Oct 2008, at 11:15, Raphael Bauduin wrote:
>
> Maybe the documentation could be a bit clearer? The example at
> http://api.rails-engines.org/classes/Engines/Rails...
> puts 'my_pluign/' in the controller route.

You're absolutely right - that is confusing. I'll change that to make
it clearer.

Thanks!

James
This topic is locked and can not be replied to.