Skip to content

Commit

Permalink
Form generator fix that is tested this time. Closes #144.
Browse files Browse the repository at this point in the history
  • Loading branch information
grimen authored and justinfrench committed Dec 2, 2009
1 parent 24ec121 commit 2e3714c
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions generators/form/form_generator.rb
Expand Up @@ -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}"))
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand Down

0 comments on commit 2e3714c

Please sign in to comment.