Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call task more than once in Rails 3 generator

I'm writing a Rails 3 generator that creates two different models. Here's a very simplified example of what I'm trying to do:

def my_generator_task
  invoke "model", ["foo"]
  invoke "model", ["bar"]
end

The problem is that the Thor invoke method only invokes a task once, so the second call to the "model" task never happens and the "bar" model is never created. Does anyone know an elegant way to accomplish this, preferably in a way that doesn't break the ability to run "rails destroy" with the generator?

like image 543
balexand Avatar asked Dec 02 '10 02:12

balexand


2 Answers

One more thought, this way it is also possible to run multiple model generator without migration

Rails::Generators.invoke("active_record:model", ["foo", "--no-migration" ])
Rails::Generators.invoke("active_record:model", ["bar", "--no-migration" ])
like image 103
bonyiii Avatar answered Sep 28 '22 18:09

bonyiii


With Thor, if you want to invoke a task withOUT dependency management, you just call it directly:

model(foo)
model(bar
like image 45
Michael Johnston Avatar answered Sep 28 '22 20:09

Michael Johnston