# Passing multiple table IDs between views

**URL:** <https://www.ruby-forum.com/t/passing-multiple-table-ids-between-views/136085>\
**Category:** Rails\
**Created:** [April 28, 2008, 8:27pm UTC](https://www.ruby-forum.com/t/passing-multiple-table-ids-between-views/136085 "2008-04-28T20:27:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![byrnejb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/d2c977/32.png) [@byrnejb](https://www.ruby-forum.com/u/byrnejb)\
**Post date:** [April 28, 2008, 8:27pm UTC](https://www.ruby-forum.com/t/passing-multiple-table-ids-between-views/136085/1 "2008-04-28T20:27:43Z")

</div>

I am having some difficulty conceiving how to best address a parameter  
passing problem I am having with rails. I am sure that this has been  
encountered and solved by others so perhaps someone can illuminate my  
ignorance.

I have the following models:

Entity  
has\_many :locations  
has\_many :site\_locations, :include =\> :sites  
has\_many :sites, :through =\> :site\_locations

Site  
has\_many :locations

Location  
belongs\_to :entity  
belongs\_to :site

Typically a site is created together with a location. The call from  
entities/index looks like this:

```
  <% if entity.locations.empty? -%>
        <%= link_to 'Add Locations',

```

new\_entity\_location\_path(entity) -%\>  
\<% else -%\>

which passes this params hash to the locations\_controller action new:

entity\_id: “3”  
action: new  
controller: locations

What I require is for the value {:entity\_id =\> ‘3’ } to be retained and  
passed back to the controller for the subsequent locations/show view. I  
tried doing this in the locations/new view:

\<%=  
hidden\_field\_tag :entity\_id, params[:entity\_id].to\_s  
-%\>

but that did not work. How do I accomplish this?

---

<div class="post-metadata">

**Author:** ![byrnejb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/d2c977/32.png) [@byrnejb](https://www.ruby-forum.com/u/byrnejb)\
**Post date:** [April 28, 2008, 8:59pm UTC](https://www.ruby-forum.com/t/passing-multiple-table-ids-between-views/136085/2 "2008-04-28T20:59:00Z")

</div>

save it to the session maybe?

On Mon, Apr 28, 2008 at 12:27 PM, James B.

---

<div class="post-metadata">

**Author:** ![byrnejb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/d2c977/32.png) [@byrnejb](https://www.ruby-forum.com/u/byrnejb)\
**Post date:** [April 28, 2008, 9:10pm UTC](https://www.ruby-forum.com/t/passing-multiple-table-ids-between-views/136085/3 "2008-04-28T21:10:50Z")

</div>

Roger P. wrote:

> save it to the session maybe?
> 
> On Mon, Apr 28, 2008 at 12:27 PM, James B.

I am not sure that that would be the correct thing to do. This is not a  
session variable but a request variable. What I have is the situation  
where location.id = ‘x’ and location.entity\_id = ‘y’. Now, in the  
locations\_controller I need to lookup entities via entity\_id.

What I desire is to pass entity\_id, which is in params[] already when  
the locations/new view is presented, from this view back to the  
locations\_controller via params. I cannot recall how do do this in the  
present instance. Perhaps I have to pass it as an optional parameter in  
the submit action. I had thought that initializing a hidden field would  
accomplish this, but evidently I was wrong.

---

<div class="post-metadata">

**Author:** ![byrnejb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/d2c977/32.png) [@byrnejb](https://www.ruby-forum.com/u/byrnejb)\
**Post date:** [April 29, 2008, 1:31am UTC](https://www.ruby-forum.com/t/passing-multiple-table-ids-between-views/136085/4 "2008-04-29T01:31:29Z")

</div>

double check your hidden field settings  
[http://betterlogic.com/roger/?p=204](http://betterlogic.com/roger/?p=204)
