class Iatelier::Controllers::Books::Create

Public Instance Methods

call(params) click to toggle source
# 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