Ticket #436 (closed defect: duplicate)

Opened 11 months ago

Last modified 10 months ago

[PATCH] Controller generator can't put controllers in directories

Reported by: cvonklei..@gmail.com Assigned to:
Priority: medium Milestone: The Future
Component: Generators Keywords:
Cc:

Description

It's useful to be able to group controllers into directories. For example, you might have /posts and /admin/posts. The controller generator isn't capable of doing this, though it looks like there is partial support (admin/posts gets turned into Admin::Posts in the error messages):

% script/generate controller admin/posts
Started merb_init.rb ...
Connecting to database...
Loading Application...
/home/cvk/projects/gutenpost/app/controllers/posts.rb:61: warning: parenthesize argument(s) for future version
Compiling routes..
wrong constant name Admin::Posts

And if we try another way...

% script/generate controller Admin::Posts
Started merb_init.rb ...
Connecting to database...
Loading Application...
/home/cvk/projects/gutenpost/app/controllers/posts.rb:61: warning: parenthesize argument(s) for future version
Compiling routes..
      exists  app/controllers
      create  app/controllers/admin::posts.rb
      create  app/views/admin::posts
      create  app/views/admin::posts/index.html.erb
      exists  app/helpers/
      create  app/helpers/admin::posts_helper.rb
  dependency  merb_controller_test
      exists    spec/controllers
      create    spec/controllers/admin::posts_spec.rb
      create    spec/views/admin::posts
      create    spec/views/admin::posts/index_html_spec.rb
      exists    spec/helpers
      create    spec/helpers/admin::posts_helper_spec.rb

Attachments

namespaced_controller_generator_fix.patch (13.2 kB) - added by j.naga..@gmail.com on 01/13/08 00:43:16.

Change History

01/10/08 23:01:15 changed by cvonklei..@gmail.com

  • owner changed.
  • component changed from Merb to Generators.

(follow-up: ↓ 4 ) 01/11/08 12:15:11 changed by j.naga..@gmail.com

The problem with the former is const_get (instead of core_ext Object.full_const_get) erroring in RubiGen?.

Even fixing that, I believe Merb only supports namespaced controllers in the sense of directories (admin/posts), and not Admin::Posts.

ie. admin/posts.rb would still define class Posts.

I managed to get a patch going which fixed the controller/view/helper generation, but it still fails because of the test generator dependency. My RubiGen?-fu is not great.

Leaving this one for hassox.

01/11/08 19:17:57 changed by iv..@gweezlebur.com

  • milestone changed from 0.5.0 to 0.5.2.

(in reply to: ↑ 2 ) 01/12/08 14:18:48 changed by cvonklei..@gmail.com

Replying to j.naga..@gmail.com:

I managed to get a patch going which fixed the controller/view/helper generation, but it still fails because of the test generator dependency. My RubiGen?-fu is not great.

Can you please attach that patch?

01/13/08 00:42:28 changed by j.naga..@gmail.com

  • summary changed from Controller generator can't put controllers in directories to [PATCH] Controller generator can't put controllers in directories.

How's this?

Output after patch:

(nagash @ justin-jones-computer)-(17:40:34)-
-(~/Sites/test_gen)- $ ./script/generate controller 'admin/hello'
      create  app/controllers/admin
      create  app/controllers/admin/hello.rb
      create  app/views/admin/hello
      create  app/views/admin/hello/index.html.erb
      create  app/helpers/admin/hello
      create  app/helpers/admin/hello_helper.rb
  dependency  merb_controller_test
      create    spec/controllers/admin
      create    spec/controllers/admin/hello_spec.rb
      create    spec/views/admin/hello
      create    spec/helpers/admin/hello
      create    spec/helpers/admin/hello_helper_spec.rb
-(nagash @ justin-jones-computer)-(17:40:47)-
-(~/Sites/test_gen)- $ ./script/generate controller world
      exists  app/controllers
      create  app/controllers/world.rb
      create  app/views/world
      create  app/views/world/index.html.erb
      create  app/helpers/world
      create  app/helpers/world_helper.rb
  dependency  merb_controller_test
      exists    spec/controllers
      create    spec/controllers/world_spec.rb
      create    spec/views/world
      create    spec/views/world/index_html_spec.rb
      create    spec/helpers/world
      create    spec/helpers/world_helper_spec.rb

01/13/08 00:43:16 changed by j.naga..@gmail.com

  • attachment namespaced_controller_generator_fix.patch added.

01/13/08 00:45:59 changed by j.naga..@gmail.com

I haven't actually tested the output (the files) yet, but just thought I'd get it out there.

01/14/08 09:39:35 changed by iv..@gweezlebur.com

  • milestone changed from 0.5.2 to 0.5.3.

01/28/08 21:06:53 changed by iv..@gweezlebur.com

  • milestone changed from 0.5.3 to The Future.

This needs testing. Let's look at it and see how to make it work with 0.9

02/11/08 13:22:05 changed by shayarne..@gmail.com

  • status changed from new to closed.
  • resolution set to duplicate.