0

I'm using axlsx (with axlsx_rails for templating).

I have this in my controller:

  def listado_publicaciones
    if params[:publicaciones]
      @Publicaciones = params[:publicaciones]
    else
      @Publicaciones = Proyecto.where("concurso_id","=",@concurso.id).as_json({:include => [:creador => {:only =>[:id],:include =>[:ficha =>{:only =>[:nombres,:apellidos], :methods => [:fullname],:include => [:publicacions => {:only =>[:id,:omitir,:anio,:titulo,:revista_nombre,:primer_autor,:autor_correspondiente,:coautor,:estado_id],:include => [:subtipo]}]}]}]})
    end
    respond_to do |format|
      format.html
      format.json { render :json => @Publicaciones}
      format.xlsx
    end
  end

(I will use JBuilder later to avoid the long @Publicaciones...)

Well, "listado_publicaciones" first shows an html view, where using angular, gets a json list of publications, and there is where the user can discard some items before generating the excel.. The user then clicks a button "To Excel" that calls an angularjs service:

@project.service 'concursos_xlsx', [
  '$resource'
  ($resource) ->
    $resource '/concursos/:id/:action.xlsx', { id: '@id' },
      listado_publicaciones:
        method: 'POST'
        params: action: 'listado_publicaciones'
] 

I use POST, because I send back a $scope with the publications I first got on a Json, this is a very large list of publications and some other data, so if I try to use GET won't work because of the long url...

Then, the same controller, "listado_publicaciones" gets the parameter publicaciones (params[:publicaciones]) and responds to format xlsx...

Then, my template called "listado_publicaciones.xlsx.axlsx" generates the excel file.... BUT I don't know how to download it... If I check the chrome developers tool, I can see this:

XHR finished loading: POST "http://localhost:3000/concursos/1/listado_publicaciones.xlsx".

And if I double click there, I can actually download the xlsx file... but I just don't know how to get the file downloaded when clicking the "To Excel" button... I've tried using "send_data", "send_file", but maybe I'm using them the wrong way... Please help, thanks!

Julio Lago
  • 283
  • 2
  • 12

0 Answers0