lib/generators/faalis/scaffold_generator.rb in faalis-1.0.0.alpha1 vs lib/generators/faalis/scaffold_generator.rb in faalis-1.0.0.alpha2

- old
+ new

@@ -22,11 +22,11 @@ # Generator Full Faalis scaffold with dashboard class ScaffoldGenerator < Rails::Generators::Base include Faalis::Generators::Concerns::RequireFields include Faalis::Generators::Concerns::Parent include Faalis::Generators::Concerns::Child - include Faalis::Generators::Concerns::JsonInput + include Faalis::Generators::Concerns::InputFile include Faalis::Generators::Concerns::ResourceName include Faalis::Generators::Concerns::ResourceFields include Faalis::Generators::Concerns::Globalize @@ -73,48 +73,46 @@ #It does not support has_many relation yet def create_model result = [] all_fields = [] relations = "\n" - fields.each do |name, type, to| case type when 'belongs_to' type_ = 'integer' if to.singularize != name relations << " belongs_to :#{name.singularize}, - :class_name => \"#{to.singularize.capitalize}\"\n" + :class_name => \"#{to.singularize.camelize}\"\n" else relations << " belongs_to :#{to.singularize}\n" end name_ = "#{name.singularize}_id" result << [name_, type_] - when 'text', 'integer', 'string', 'boolean', 'datetime', 'date', 'float' + when 'text', 'integer', 'string', 'boolean', 'datetime', 'time', 'date', 'float' result << [name, type] when 'image' generate "paperclicp #{resource_data['name']} #{name}" relations << " has_attached_file :#{name}\n" relations << " validates_attachment_content_type :#{name}, content_type: %w(image/jpeg image/jpg image/png), - less_than: 1.megabytes]\n" + less_than: 1.megabytes\n" # TODO: Run this generator just once for all images `rails generate paperclip #{resource_data['name']} #{name}` when 'tag' rake "rake acts_as_taggable_on_engine:install:migrations" relations << " acts_as_taggable_on :#{name}\n" result << [name, 'string'] when 'in' result << [name, 'string'] - when 'has_many' - relations << " has_and_belongs_to_many :#{to}\n" + when 'has_and_belongs_to_many' + relations << " has_and_belongs_to_many :#{to.pluralize}\n" say_status 'warn', "There is a many to many relation between #{resource_data['name']} and #{to}, You should create it manually in model files" - end end if parent? parents.each do |parent| @@ -159,11 +157,10 @@ end #Invoke Faalis list view generator def create_list_view - invoke 'faalis:js:list_view', [jsonfile] - + invoke 'faalis:js:list_view', [input_file] end def create_globalize_migration `rails g migration add_globalize_to_#{resource_data["name"].underscore} ` Dir["#{Rails.root}/db/migrate/**/*globalize*.rb"].each {|file| require file }