We've moved discussions to Discord

Recommended approach for setting account reference from associated model

Ed Pritchard
Hello,
I'm interested to know what the recommendation is for creating a model and associate it with an account? For example, suppose I have a model like the following.

class JobPhase < ApplicationRecord
  acts_as_tenant :account
  belongs_to :account
end

I've generated a scaffold for this so that I can create new Job Phases. The _form.html.erb for this just includes a field for the account_id, but I don't think that's safe. I see in other examples that you have set up a helper path, like this for Account Invitations.


      <%= form_with(model: @account_invitation, url: account_account_invitations_path(@account)) do |form| %>

Is this the recommended approach, or is it wiser to only accept params in the controller for things like attributes on the model, and do something like 

phase_attributes = job_phase_params.merge(account_id: Current.account_id)    
@job_phase = JobPhase.new(job_phase_params)

Thanks for your help!
Ed Pritchard
Actually, I'm finding that not even including account ID in my JobPhase.new(job_phase_params) works, already. I'm guessing this is because of the ActsAsTenant gem doing all the work under the hood?
Notifications
You’re not receiving notifications from this thread.