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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:03:38+00:00 2026-05-26T16:03:38+00:00

I have a Rails view that produces a HTML report based on the user

  • 0

I have a Rails view that produces a HTML report based on the user having selected a date range of the report – and all is good with that.

If the users likes what they see, there’s a button to export that same report as csv.

My problem is how to conveniently pass the date range previously selected by the user. I’ve read various stackoverflow questions/answers about passing parameters via link_to, and this works somewhat, but the date is sent as a text string, and what I really need is for the date to be passed as a Date object.

Here’s my current link_to, which passes the date params as strings:

<%= link_to image_tag("Buttons/ExportReport.png", :border => 0),
      export_sales_path(:start => @start_date,
                        :end => @end_date,
                        :sales => @items) %>

I’d appreciate it if someone could tell me how to pass an instance of an object via link_to.

Thanks for reading.

  • 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-05-26T16:03:39+00:00Added an answer on May 26, 2026 at 4:03 pm

    You can’t pass objects in URLs. For one, there’s a limit of about 1500 bytes on the length of the URL, and secondly, Ruby objects are only relevant to the process that created them.

    The important thing to remember here is there is no presumption that the process that will be receiving your request will be the same as the one that generated the page with the link on it. By design, Ruby on Rails starts with a clean slate for each incoming request and has no knowledge apart from what it can extract from three basic facilities: the cache, the session, and your database.

    For things like @items, what you need to do is save this set somewhere, such as in a database, and put a token or identifier in the URL that links to this saved set, or convert it to a representation that fits in the URL. If the list is small, you could always send @items.collect(&:id).join(',') and then decode that on the receiving end.

    If all you need is a temporary store, Memcache, which can be used in the Rails.cache subsystem, serves as a good place to put things like this.

    Since dates are easily represented as integers, you could always supply those as the parameters. An approach might look like this:

    <%= link_to image_tag("Buttons/ExportReport.png", :border => 0),
        export_sales_path(
          :start => @start_date.to_i,
          :end => @end_date.to_i,
          :sales => @items.collect(&:id).join(',')
        ) %>
    

    You can switch this to a POST-style request which will allow you to supply a very long list of items if required.

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

Sidebar

Related Questions

I have a nested form in a rails view that is called like this
I have an application, built using MVC, that produces a view which delivers summary
Using: Rails 3.1.1 I have a controller/model/view called Category that is built up on
I have a rails app that shows statistics based on an employee's daily production.
I have an XML view in a rails app, and need to insert in
this time it's about Ruby On Rails. I have a form in the view
I'm making a simple search form in rails. In my search view I have
I have a rails application where each user has a separate database. (taking Joel
I have a rails model that looks something like this: class Recipe < ActiveRecord::Base
I have Rails 3.1.2 app with a hierarchical relationship that looks like this: Categories

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.