Permalink
Browse files

Form generator fix that is tested this time. Closes #144.

  • Loading branch information...
1 parent 24ec121 commit 2e3714cd6f90559cc72354c0480acb00de1499ee @grimen grimen committed with Dec 2, 2009
Showing with 10 additions and 4 deletions.
  1. +10 −4 generators/form/form_generator.rb
@@ -39,10 +39,11 @@ def initialize(runtime_args, runtime_options = {})
def manifest
record do |m|
if options[:partial]
+ controller_and_view_path = options[:controller] || File.join(controller_class_path, controller_file_name)
# Ensure directory exists.
- m.directory File.join(VIEWS_PATH, controller_class_path, controller_file_name)
+ m.directory File.join(VIEWS_PATH, controller_and_view_path)
# Create a form partial for the model as "_form" in it's views path.
- m.template "view__form.html.#{template_type}", File.join(VIEWS_PATH, controller_file_name, "_form.html.#{template_type}")
+ m.template "view__form.html.#{template_type}", File.join(VIEWS_PATH, controller_and_view_path, "_form.html.#{template_type}")
else
# Load template file, and render without saving to file
template = File.read(File.join(source_root, "view__form.html.#{template_type}"))
@@ -85,8 +86,8 @@ def save_to_clipboard(data)
# Add additional model attributes if specified in args - probably not that common scenario.
def attributes
- # Get columns for the requested model
- existing_attributes = @class_name.split('::').last.constantize.content_columns.reject { |column| IGNORED_COLUMNS.include?(column.name.to_sym) }
+ # Get columns for the requested model.
+ existing_attributes = @class_name.constantize.content_columns.reject { |column| IGNORED_COLUMNS.include?(column.name.to_sym) }
@args = super + existing_attributes
end
@@ -105,6 +106,11 @@ def add_options!(opt)
"Save generated output directly to a form partial (app/views/{resource}/_form.html.*).") do |v|
options[:partial] = v
end
+
+ opt.on('--controller CONTROLLER_PATH',
+ "Specify a non-standard controller for the specified model (e.g. admin/posts).") do |v|
+ options[:controller] = v if v.present?
+ end
end
def banner

0 comments on commit 2e3714c

Please sign in to comment.