:id vs. a_id:

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
. . .
. . .

def this_a
@a = A.find(params[:a_id])

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.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs