Class: Iatelier::Controllers::Books::Update

Inherits:
Object
  • Object
show all
Includes:
Action, DbConnector
Defined in:
lib/iatelier/controllers/books/update.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
# File 'lib/iatelier/controllers/books/update.rb', line 8

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

    # setting up the book
 @book = Object.const_get(params[:book_type].capitalize).find(params[:id])
    @book.namespace = @database

    @book.dimensions.each do |dimension|
    			if @book.public_send(dimension.to_sym)
method_name = 'revise_' + dimension
    			else
method_name = 'setup_' + dimension
    			end
    			@book.public_send(method_name.to_sym, params)
    		end
    		@book.dimensions.each do |dimension|
        action = @book.public_send(dimension.to_sym)
    			if !action.save
            @errors = action.errors.messages
            self.status = 422
        end
    		end
    		@book.sync_keywords params
    		@book.sync_individuals params
    		@book.sync_content params
    		@book.store_attachment params
end