Domanda

Following http://railscasts.com/episodes/362-exporting-csv-and-excel

But using rails 4, and ruby 2.0.

My rake routes is:

Prefix Verb     URI Pattern                            Controller#Action
root GET      /                                      access#index
     GET|POST /:controller(/:action(/:id(.:format))) :controller#:action

and I've updated my mime file to include:

Mime::Type.register "application/vnd.ms-excel", :xls

(I've also tried this, per the video:)

Mime::Type.register "application/xls", :xls

data.xls.erb exists in my views, and I've defined data in my answers_controller like this:

def data
    @data_fields = DataField.all
    @users = User.all

    respond_to do |format|
      format.html
      format.xls
    end
end

yet when I visit http://localhost:3000/answers/data.xls I get No route matches [GET] "/answers/data.xls"

È stato utile?

Soluzione

Your URL

http://localhost:3000/answers/data.xls

doesn't match the route

GET|POST /:controller(/:action(/:id(.:format))) :controller#:action

Note that the route isn't expecting data.xls, it's expecting data/:id.xls.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top