Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

partial generation doesn't use namespace #144

Closed
sauberia opened this Issue · 11 comments

3 participants

@sauberia

If I prefix the model name with the controller namespace the generator creates the namespace directory as expected but then attempts to create the partial in a directory one up from that:

script/generate form admin/thing --partial --haml

create app/views/admin/things

create app/views/things/_form.html.haml

No such file or directory - /Users/marc/Sites/test/app/views/things/_form.html.haml

If I add the controller_class_path variable in the following line from form_generater.rb:

m.template "view__form.html.#{template_type}", File.join(VIEWS_PATH, controller_class_path, controller_file_name, "_form.html.#{template_type}")

It attempts to create the file in the correct directory but then I get the error

uninitialized constant Admin::Thing

I guess it thinks admin is the model module and the controller namespace or summink.

I'm a wee bit out of m depth here so this may not be an issue.

@sauberia

I've ended up changing:
@class_name.constantize.content_columns.reject
to
@singular_name.classify.constantize.content_columns.reject

and it works for my purposes

@grimen

OK, this is not really a bug - because this is somewhat odd scenario. You should specify the model name, I'm 90% sure this is the way Rails handles it as well. The form layout don't depend on any details in the controller, rather the model. Closing.

@justinfrench
Owner

Hang on, I agree that the arg is intended to only be the model name, but...

  1. the code should be more resilient to such misconceptions -- perhaps throw an error if there's a slash or :: namespace in the model param?

  2. it's still a valid suggestion that you can choose where in the view hierarchy this should go, perhaps with a second arg?

    script/generate form thing admin/thing --partial

?

@grimen

OK.

@sauberia

This doesn't seem to do the trick:

script/generate form admin/thing --partial --haml

create app/views/admin/things

create app/views/things/_form.html.haml

No such file or directory - /Users/marc/Sites/test/app/views/things/_form.html.haml

sg form admin::thing --partial --haml

exists app/views/admin/things

create app/views/things/_form.html.haml

No such file or directory - /Users/marc/Sites/test/app/views/things/_form.html.haml

@grimen

Odd, I think I need to spend more time on this one...Rails generator internals is a mess (really) - good thing Rails 3 will rock a shiny new one.

@grimen

This works for me, but I had to add a optional flag (--controller CONTROLLER_PATH) to support all three major cases:

http://github.com/grimen/formtastic/commit/827c6c786acdab8864c4dffcaf58958b72e307dc

Meaning: Model might be namespaced - or might not, and that could be a mess in Ruby 1.9.

@sauberia

Brilliant!

script/generate form thing --partial --controller admin/things

exists app/views/admin/things

create app/views/admin/things/_form.html.erb

Appreciated :)

@grimen

Fix for the form generator: Allows controller namespace to be specified, but strips out the namespace for the model. Closed by 24ec121.

@justinfrench
Owner

pulled in, closing

@zuf zuf referenced this issue from a commit in zuf/formtastic
@grimen grimen Fix for the form generator: Allows controller namespace to be specifi…
…ed, but strips out the namespace for the model. Closes #144.
24ec121
@zuf zuf referenced this issue from a commit in zuf/formtastic
@grimen grimen Form generator fix that is tested this time. Closes #144. 2e3714c
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.