Permalink
Browse files

generator now checks if has_many model exists

  • Loading branch information...
1 parent 86c5cbb commit 2f15223538a82c0daeda9853c9effb9c2726c6c5 @careljonkhout committed May 24, 2012
Showing with 16 additions and 0 deletions.
  1. +16 −0 lib/generators/inline_forms_generator.rb
@@ -1,6 +1,7 @@
# -*- encoding : utf-8 -*-
require File.expand_path(File.join(File.dirname(__FILE__),'../app/helpers/inline_forms_helper.rb'))
module InlineForms
+
# == Usage
# This generator generates a migration, a model and a controller.
#
@@ -90,6 +91,20 @@ def set_some_flags
@flag_create_resource_route = @flag_create_model
end
+ def verify_presence_of_has_many_model
+ for attribute in attributes
+ if [:has_many, :has_many_destroy].include? attribute.type
+ model_name = attribute.name.singularize.camelize
+ begin
+ eval model_name
+ rescue NameError
+ raise "Can't find model \"#{model_name}\" " +
+ "which you referred to in a #{attribute.type} relation"
+ end
+ end
+ end
+ end
+
def generate_model
if @flag_create_model
@belongs_to = "\n"
@@ -167,6 +182,7 @@ def generate_model
end
end
+
def generate_resource_route
route "resources :#{resource_name} do\n post 'revert', :on => :member\nend" if @flag_create_resource_route
end

0 comments on commit 2f15223

Please sign in to comment.