Class: ModelGen::EntitiesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/model_gen/entities_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#available_models

Instance Method Details

#createObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/controllers/model_gen/entities_controller.rb', line 8

def create
  @errors = []
  if available_models.include?(params[:name].capitalize)
    @errors << "Model with name #{params[:name]} already exists."
    render 'new'
  else
    command = "rails g model #{params[:name].downcase}"
    params[:fields].each do |index, field|
      command = command + " #{field[:name].downcase}:#{field[:type].downcase}"
    end
    system command
    system 'rake db:migrate'
    redirect_to new_entity_path
  end
end

#newObject



5
6
# File 'app/controllers/model_gen/entities_controller.rb', line 5

def new
end