Class: FafactoriesController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/fafactories_controller.rb

Instance Method Summary collapse

Instance Method Details

#create_instanceObject

POST a new instance of the type of model requested

Parameters

model<String>

The model to create a new instance of

data<Hash>

A hash of the attributes for the model



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

def create_instance
  obj = Module.const_get(params["hash"]["model"].to_sym).new

  params["hash"]["data"].each do |key, value|
    obj.send(:"#{key}=", value)
  end

  obj.save!
  
  respond_to do |format|
    format.xml do
      render :xml => obj, :status => :created
    end
  end
end

#findObject

Find the instance of model identified by id and return it’s xml.

Parameters

id<Integer>

The id of the instance to look up.

model<String>

The model to look up the instance for.

Returns



59
60
61
62
63
64
65
66
# File 'app/controllers/fafactories_controller.rb', line 59

def find
  obj = Module.const_get(params[:model].to_sym).find(params[:id])
  respond_to do |format|
    format.xml do
      render :xml => obj
    end
  end
end

#purgeObject

Purges the test database



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'app/controllers/fafactories_controller.rb', line 26

def purge

  # We have to disconnect the connection for active record because the
  # connection doesn't make it through the fork, and the rake task will
  # do it's own database load, etc anyway
  dbconfig = ActiveRecord::Base.remove_connection
  pid = fork do
  
    require 'rake'
    require 'rake/testtask'
    require 'rake/rdoctask'

    require 'tasks/rails'
  
  
    Rake::Task['db:test:load'].invoke
  end
  ActiveRecord::Base.establish_connection(dbconfig)
  Process.wait(pid)

  respond_to do |format|
    format.xml { head :ok }
  end
end