# :id vs. a\_id:

**URL:** <https://www.ruby-forum.com/t/id-vs-a-id/181945>\
**Category:** Rails\
**Created:** [January 20, 2010, 3:30pm UTC](https://www.ruby-forum.com/t/id-vs-a-id/181945 "2010-01-20T15:30:35Z")\
**Posts on this page:** 1\
**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:** [January 20, 2010, 3:30pm UTC](https://www.ruby-forum.com/t/id-vs-a-id/181945/1 "2010-01-20T15:30:35Z")

</div>

I have a controller a\_bs\_controller that usually has to find A by  
a\_id:. So, among others, it has these methods:

def update  
this\_a  
. . .  
end  
. . .

def this\_a  
@a = A.find(params[:a\_id])  
end

My difficulty arises in that sometimes this controller is passed :a\_id  
in a nested hash as [:a]{:id], with or without :a\_id in another  
portion of a nested hash. .

params =\> { :controller =\> :a\_bs, . . . , :a =\> { :id =\> ‘x’}, :c  
=\> ‘value’, :b =\> { a\_id =\> ‘x’, :description =\> ‘value’ }}

What I would really like to do is to discover some method of setting  
params[:a\_id] in the views that return it as a nested hash otherwise.  
Failing that I need to extract the :id of :a from whatever params I am  
handed. I should never receive :a\_id simply as :id in a simple hash  
as is the usual case for as\_controller.

I tried to solve this in the view by modifying the params hash both  
directly and through a hidden field. In both cases the result was  
nested inside of a hash named :b. I have also played with  
constructing a method to walk down the hashes to find :a\_id, however,  
I have put that aside for now to see if my problem is really my  
approach to the solution.
