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 8688407
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T23:21:18+00:00 2026-06-12T23:21:18+00:00

I’m performing AJAX search in my Rails application. Here is code from controller: def

  • 0

I’m performing AJAX search in my Rails application. Here is code from controller:

def show
@website = Website.find(params[:id])
if (current_user.id != @website.user_id)
  redirect_to root_path
  flash[:notice] = 'You are not owner!'
end
if params[:report] && params[:report][:start_date] && params[:report][:end_date]
  @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

but when I’m trying to generate Excel document it alway goes to branch without params, because there are no params in URL.

One man reccomend me to use this post. I tried to implement it, but couldn’t.

I don’t understand this post enough, I just can’t get where data is passing(spreadsheet gem)

Here is code:

 def export

  @website = Website.last

  @data = @website.performance_reports

  report = Spreadsheet::Workbook.new

  spreadsheet = StringIO.new

  contruct_body(spreadsheet, @data)

  report.write spreadsheet 

  send_data spreadsheet.string, :filename => "yourfile.xls", :type =>  "application/vnd.ms-excel"


 end

and it gives me error:

 undefined method `contruct_body'

Code from view:

    <%= form_tag( url_for, :method => :get, :id => "report") do%>
      ...show action posted above...
     <% end %>

    <%= link_to export_path do%>
     <b>Export</b>
    <% end %>
   ...working code without AJAX...
       <%= link_to url_for(request.parameters.merge({:format => :xls}))  do%>
    <b>Export</b>
    <% end %>

Please tell me where is my mistake or suggest ano

  • 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-12T23:21:20+00:00Added an answer on June 12, 2026 at 11:21 pm

    For the first problem, you need to show the view code and the path ajax is taking. Give us more information how the excel is being called.

    For the second issue, you need to define that method. Specify how you will populate the spreadsheet with the data. Here is the guide. https://github.com/zdavatz/spreadsheet/blob/master/GUIDE.txt

    == Writing is easy
    As before, make sure you have Spreadsheet required and the client_encoding
    set. Then make a new Workbook:

      book = Spreadsheet::Workbook.new
    

    Add a Worksheet and you’re good to go:

      sheet1 = book.create_worksheet
    

    This will create a Worksheet with the Name “Worksheet1”. If you prefer another
    name, you may do either of the following:

      sheet2 = book.create_worksheet :name => 'My Second Worksheet'
      sheet1.name = 'My First Worksheet'
    

    Now, add data to the Worksheet, using either Worksheet#[]=,
    Worksheet#update_row, or work directly on Row using any of the Array-Methods
    that modify an Array in place:

      sheet1.row(0).concat %w{Name Country Acknowlegement}
      sheet1[1,0] = 'Japan'
      row = sheet1.row(1)
      row.push 'Creator of Ruby'
      row.unshift 'Yukihiro Matsumoto'
      sheet1.row(2).replace [ 'Daniel J. Berger', 'U.S.A.',
                              'Author of original code for Spreadsheet::Excel' ]
      sheet1.row(3).push 'Charles Lowe', 'Author of the ruby-ole Library'
      sheet1.row(3).insert 1, 'Unknown'
      sheet1.update_row 4, 'Hannes Wyss', 'Switzerland', 'Author'
    

    Add some Formatting for flavour:

      sheet1.row(0).height = 18
    
      format = Spreadsheet::Format.new :color => :blue,
                                       :weight => :bold,
                                       :size => 18
      sheet1.row(0).default_format = format
    
      bold = Spreadsheet::Format.new :weight => :bold
      4.times do |x| sheet1.row(x + 1).set_format(0, bold) end
    

    And finally, write the Excel File:

      book.write '/path/to/output/excel-file.xls'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have a view passing on information from a database: def serve_article(request, id): served_article
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

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.