Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8524029
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T07:34:33+00:00 2026-06-11T07:34:33+00:00

Hello! I have this trouble: I’m searching reports by date and in html view

  • 0

Hello!

I have this trouble: I’m searching reports by date and in html view everything is alright, BUT when I’m rendering xls view error appear, because it didn’t receive params, so I need to pass them in URL for xls link_to generator.

My controller:

def show
  @website = Website.find(params[:id])
  if params[:report] && params[:report][:start_date] && params[:report][:end_date]
    #search_by_created_at
    @performance_reports = @website.performance_reports.where("created_at between ? and ?", params[:report][:start_date].to_date, params[:report][:end_date].to_date)
  else
    @performance_reports = @website.performance_reports
  end
  respond_to do |format|
    format.html # index.html.erb
    format.xls
    format.xml  { render :xml => @performance_reports }
  end
end

and my generated url looks like:

 http://127.0.0.1:3000/websites/25/performance_reports/show?utf8=%E2%9C%93&report[end_date]=07%2F09%2F2012&report[start_date]=04%2F09%2F2012&commit=Run+Report

mine xls url is generated like this:

 <%= link_to url_for(:format => 'xls')  do%>
   <%= image_tag("excel.png", :id => "analytics",:size => '21x23')%> <b>Export</b>
 <% end %>

result:

http://127.0.0.1:3000/websites/25/performance_reports/show

Any help will be appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T07:34:35+00:00Added an answer on June 11, 2026 at 7:34 am

    xls in not available by default.

    Add this:

    gem "spreadsheet"
    gem "to_xls", :git => "https://github.com/dblock/to_xls.git", :branch => "to-xls-on-models"
    

    Register the Excel MIME type in config/initializers/mime_types.rb by adding this:

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

    Add an as_xls method to model that you want to export for the fields you want.
    For example for a User model you might have:

    def as_xls(options = {})
      {
          "Id" => id.to_s,
          "Name" => name,
          "E-Mail" => email,
          "Joined" => created_at,
          "Last Signed In" => last_sign_in_at,
          "Sign In Count" => sign_in_count
      }
    end
    

    Add code to the controller:

    def index
      @users = User.all
      respond_to do |format|
        format.html
        format.xls { send_data @users.to_xls, content_type: 'application/vnd.ms-excel', filename: 'users.xls' }
      end
    end
    

    Provide a link:

    = link_to 'Export', users_path(request.parameters.merge({:format => :xls}))
    

    All code should have a test. You could do something like this:

    describe "GET index.xls" do
      it "creates an Excel spreadsheet with all users" do      
        user = Fabricate :user
        get :index, :format => :xls
        response.headers['Content-Type'].should == "application/vnd.ms-excel"
        s = Spreadsheet.open(StringIO.new(response.body))
        s.worksheets.count.should == 1
        w = s.worksheet(0)
        w.should_not be_nil
        w.row(0)[0].should == "Id"
        w.row(1)[0].should == user.id.to_s
        w.row(0)[1].should == "Name"
        w.row(1)[1].should == user.name
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello I have this trouble: I have two sections in my header, but when
Hello I have been having trouble with this for a while now. I have
Hello I have a trouble customizing a background of the grouped table view.. Here's
Hello I'm having trouble figuring this out. I have these structs and classes. struct
I'm having some trouble figuring this out. I have the following CSV string hello
hello i have this question i was trying to find a way to call
Hello I have this code class Triplets { public: int nVal1; int nVal2; NodeT
Hello i have this form filling javascript: function onLine(code,nn) { document.writeform.bericht.value+=code; document.writeform.bericht.focus(); document.writeform.nickname.value+=nn; write1();
Hello I have this list that i am working on. When i move the
hello I have this code that use to sort a datatable. Dim sortingIndex As

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.