Class: Iatelier::Controllers::Books::Create

Inherits:
Object
  • Object
show all
Includes:
Action, DbConnector
Defined in:
lib/iatelier/controllers/books/create.rb

Instance Method Summary collapse

Methods included from DbConnector

#set_database

Instance Method Details

#call(params) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/iatelier/controllers/books/create.rb', line 8

def call(params)
    # [optional] setting the database
    @database = params.get(:database)
 self.set_database @database

    #
			@book = Object.const_get(params[:book_type].capitalize).new
    @book.namespace = database

    # p 'starting everything'
    @book.dimensions.each do |dimension|
        method_name = 'setup_' + dimension
        action = @book.public_send(method_name.to_sym, params)
        p 'what is the status = ' + action.valid?.to_s
        if !action.valid?
            puts 'the error is ' + action.errors.messages.to_s
            @errors = action.errors.messages
            self.status = 422
            return 'caught an error!'
        end
    end

    @book.save

    @book.dimensions.each do |dimension|
        action = @book.public_send(dimension.to_sym)
    			if !action.save
            @errors = action.errors.messages
            self.status = 422
            return 'caught an error!'
        end
    		end

    @book.sync_keywords params
    		@book.sync_individuals params
    		@book.sync_content params
    		@book.store_attachment params

    redirect_to '/iatelier/' + @database + '/' + params[:book_type]
end