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

The Archive Base Latest Questions

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

I need to have a button to save the current web site (just like

  • 0

I need to have a button to save the current web site (just like clicking on “Save as”), I created a method in the controller which works great for any external site (like http://www.google.com) but doesn’t work for the sites inside my application, I get a timeout error!. This has no explanation to me 🙁

Any clue what is the issue?

#CONTROLLER FILE
def save_current_page
  # =>  Using MECHANIZE
  agent = Mechanize.new
  page = agent.get request.referer
  send_data(page.content, :filename => "filename.txt")
end

I tried also Open URI, same problem!

#CONTROLLER FILE
def save_current_page
 # => USANDO OPEN URI
 send_data(open(request.referer).read, :filename => "filename.txt")
end

I’m using rails 3.2 and ruby 1.9, any help is appreciated, I already spent like 10 hours trying to make it work!!

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

    After several hours and lots of other posts I got to a final solution:

    Bricker is right in that it is not possible for rails to render more than once in a call, as taken from http://guides.rubyonrails.org/layouts_and_rendering.html “Can only render or redirect once per action”

    The site also states “The rule is that if you do not explicitly render something at the end of a controller action, Rails will automatically look for the action_name.html.erb template in the controller’s view path and render it.”

    Then, the solution that worked great for me was to tell the controller to render to a string if a download flag (download=true) was set in :params (I also use request.url to have it working from any view in my application)

    View:

    = link_to 'Download', request.url+"&downloadexcel=true", :class => 'btn btn-primary btn-block'
    

    Controller:

    def acontrolleraction
      #some controller code here
      if params[:downloadexcel]
        save_page_xls
      else
        # render normally
      end
    end
    
    
    def save_page_xls
      #TRESCLOUD - we create a proper name for the file
      path = URI(request.referer).path.gsub(/[^0-9a-z]/i, '')
      query = URI(request.referer).query.gsub(/[^0-9a-z]/i, '')
      filename = @project_data['NOMBRE']+"_"+path+"_"+query+".xls"
    
      #TRESCLOUD - we render the page into a variable and process it
      page = render_to_string
    
      #TRESCLOUD - we send the file for download!
      send_data(page, :filename => filename, :type => "application/xls")
    end
    

    Thanks for your tips!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a button called as Sync . On clicking on it, I need
i have a form button in the form,which i need to perform basic action
I need a button-like control that can have a Checked property, so that when
I am using an user control which have a button named 'btn_Save'.I need to
I need to have a button whose text is underlined and the only way
I need to have only one button in showConfirmDialog . I tried this: int
I have a Button on appwidget, that I need to 'enable'/'disable' programmatically from a
I have a button,Linkbutton and an ModalPopup. If I click button1 I need to
I have a hidden button on a form that I need to click in
I have a Flex button. I need one color on the left and another

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.