Class: Formtastic::FormGenerator
- Inherits:
-
Rails::Generators::NamedBase
- Object
- Rails::Generators::NamedBase
- Formtastic::FormGenerator
- Defined in:
- lib/generators/formtastic/form/form_generator.rb
Overview
Generates a Formtastic form partial based on an existing model. It will not overwrite existing files without confirmation.
Instance Method Summary collapse
Instance Method Details
#create_or_show ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/generators/formtastic/form/form_generator.rb', line 36 def create_or_show @attributes = reflected_attributes if @attributes.empty? if [:copy] template = File.read("#{self.class.source_root}/_form.html.#{template_type}") erb = ERB.new(template, nil, '-') generated_code = erb.result(binding).strip rescue nil puts "The following code has been to the clipboard, just paste it in your views:" if save_to_clipboard(generated_code) puts generated_code || "Error: Nothing generated. Does the model exist?" else empty_directory "app/views/#{controller_path}" template "_form.html.#{template_type}", "app/views/#{controller_path}/_form.html.#{template_type}" end end |