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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:33:45+00:00 2026-05-20T10:33:45+00:00

Hey. I think I am in a mind trap here. I am using Rails

  • 0

Hey. I think I am in a mind trap here. I am using Rails 2. In the index view of my controller I set up something like

def index
  @posts = Post.all
end

so that I can use @posts in my index, e.g. each-do. Id like to pass @posts to a custom made view, in where I can use the same variable again. This I want to do over a link from the index view. Something like that:

link_to "newpage", {:controller => 'posts', :action => 'newmethod', :param => @posts}

What I have created so far is a new method in my Post controller. A new view. And and a new route to that site. Any suggestions? thx for your time

  • 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-20T10:33:45+00:00Added an answer on May 20, 2026 at 10:33 am

    You’re going to have to collapse those values into something that will fit in a URL, then decode them later. For instance:

    # Put this in your helper method module PostsHelper
    def post_ids
      @posts.collect(&:id).join(',')
    end
    

    Your adjusted link would be:

    link_to "newpage", {:controller => 'posts', :action => 'newmethod', :param => post_ids }
    

    When you fetch the next page you’ll need to decode these by retrieving them again:

    @posts = Posts.find(params[:param].split(/,/))
    

    There’s no way to pass an instance variable between requests because they are explicitly cleared out.

    As a note, try and use the generated route methods instead of the hash-style declaration. You would probably have a route already listed in rake routes:

    # Instead of { :controller => 'posts', :action => 'new', :param => post_ids }
    new_post_path(:param => post_ids)
    

    These generated methods are much more readable in practice and have the advantage of being configurable later if you want to re-interpret what they mean by adjusting your routing table.

    Another note is that if the list of IDs gets very large, you may not be able to encode them into a URL as the limit is about 1500 bytes. You may instead have to serialize the conditions used to generate the list in the first place and then re-run those again later. So long as you’re dealing with tens of items and not hundreds you should be okay, though.

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

Sidebar

Related Questions

Hey everyone, I'm using Virtual PC and working with a virtual hard disk (*.vhd)
Hey, I'm using Levenshteins algorithm to get distance between source and target string. also
Hey right now I'm using jQuery and I have some global variables to hold
Hey! I think this is a simple question for you. Most of the system
Hey, I think the title sums it, but still. I need to extract the
Hey, I think I'm going about this the wrong way, but have tried many
Hey I was wondering... I am using the pydev with eclipse and I'm really
Hey, i think this is an easy question. I have a URL and i
Hey, I think the best way to ask this question is to show what
The easiest way I could think of is a for loop: var arr=[[hey,oh],[scar,tissue],[other,side]]; var

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.