Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check parent controller name in nested controller

I am building a Rails 3.2 app. In this app I got two controllers sharing the same nested controller (transactions).

The paths looks like this:

http://localhost:3003/admin/purchases/6/transactions

and like this

http://localhost:3003/admin/subscriptions/6/transactions

In the transactions index action, how can I check if the parent is either purchases or subscriptions?

like image 324
Jonathan Clark Avatar asked Mar 18 '26 13:03

Jonathan Clark


1 Answers

Assuming you have defined this as a nested resource in your routes file, you could check for params[:purchase_id] and params[:subscription_id]:

if params[:purchase_id]
  # parent is purchase
elsif params[:subscription_id]
  # parent is subscription
end
like image 156
Mischa Avatar answered Mar 20 '26 03:03

Mischa



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!