Rails - actions_as_list with multiple models

I managed to use it act_as_listwith my models (it was pretty simple) one by one, but now I have a problem.

In my application there are 3 models: Facility, Serviceand Activity. I need to use acts_as_listin combining them ... is it possible to do this?

Hope my question is clear.

+5
source share
1 answer

You should use the fourth model with polymorphic association, and then put the list in it.

Check out polymorphic associations first to understand this: http://guides.rubyonrails.org/association_basics.html#polymorphic-associations

Now you need a class that looks like this:

class Position < ActiveRecord::Base
  belongs_to :positionable, polymorphic: true
end

, :

class CreatePositions < ActiveRecord::Migration
  def change
    create_table :position do |t|
      t.integer :positionable_id
      t.string  :positionable_type
      t.timestamps
    end
  end
end

:

class Facility < ActiveRecord::Base
  has_one :position, as: :positionable
  # ...
end
+3

All Articles