I have a method to create folder on Google drive as soon a create method is hit. I want the folder to created once the batch is saved. Below is the code Im using. In the below method page redirects as soon as it is authorised. So requesting for workarround
def create
client = Signet::OAuth2::Client.new(
:authorization_uri => 'http://ift.tt/IlrJzQ',
:token_credential_uri => 'http://ift.tt/1yJFQ0y',
:client_id => "XXXXXX-XXXXXX",
:client_secret => "XXXXXX-XXX",
:scope => 'http://ift.tt/JALASw',
:redirect_uri => "http://localhost:3000/batches/"
)
@batch = Batch.new(params[:batch])
respond_to do |format|
if @batch.save
if params[:code].present?
client.code = request['code']
client.fetch_access_token!
x = Google::Apis::DriveV3::DriveService.new
x.authorization = client
files = x.list_files(options: { authorization: client })
file_metadata = {
name: 'Batches-new',
mime_type: 'application/vnd.google-apps.folder',
}
file = x.create_file(file_metadata, fields: 'id')
Rails.logger.debug "Folder Id: #{file.id}"
else
format.html {redirect_to client.authorization_uri.to_s}
end
format.html {redirect_to batches_path(trek_id: @batch.trek_id), notice: 'Batch was successfully created.' }
format.json { render json: @batch, status: :created, location: @batch }
else
format.html {
flash.now[:error] = @batch.errors.full_messages
render action: "new"
}
format.json { render json: @batch.errors, status: :unprocessable_entity }
end
end
end
after hiting the create action page navigates to index page without creating folder. How to make folder gets created before going to index page. Thanx in advance.
Aucun commentaire:
Enregistrer un commentaire