My setup:
class ServiceUser < ActiveRecord::Base
belongs_to :user
belongs_to :service
enum status: [ :unavailable, :available ]
end
class Service < ActiveRecord::Base
has_many :service_users
has_many :users, :through => :service_users
end
class User < ActiveRecord::Base
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
has_many :service_users
has_many :services, :through => :service_users
end
From the ServiceUser model i can call the status field, in my case available and unavailable. In my app i'm listing all the users for a specific service with:
@service.users
But now i want to show the status for each user from the ServiceUser model. What is the best way to do is?
Also i want to make a form for the ServiceUser model to make a new relation between the service and the current user:
ServiceUser.new(service_id: @service.id, user_id: current_user.id, status: 1)
What do i need to specify in the form for?