ruby on rails - option_groups_from_collection_for_select specific method group -


I want to create a dynamic selection form in ActiveAdmin. Assuming that the user has multiple commands and each order has a feature payout (boolean), after selecting the user, the next sealiton is an order payment by this user.

  option_groups_from_collection_for_select (User.order (: Email) ,: Order, Email ,: ID ,: Name)  

But I only want to display a paid order Do not get the way.

You can define a method on the user model : The command will substitute the argument that you are passing. This method should return the order that is paid.

Try to use a union declaration (this will add the method to you):

  class users & lt; ActiveRecord :: Base is has_many: Order has_many: paid_orders, class_name: 'order', - & gt; {Where pay: true} end  

Your user will now have a payment_order method in which command > Where their payment attribute is true .

Change your form assistant to:

  option_groups_from_collection_for_select (user.  

should do this.

This idea is here that the : Pay_orders argument is on the example of a method named user you want free to define any method, even so Also manually:

  class user & lt; ActiveRecord :: base has_many: Order DR def_orders command, where to make payment: correct termination  

Comments