質問

I have a model (Candidate) that I need to keep track of changes, version diffs, who changed it and any comments they had regarding the change. I love paper_trail and it is exactly what I need in almost every way, but I'm wondering what the best way to store "change comments" is. I've been thinking of implementing one of three options:

  1. Add a comments column to my versions table. If I went this way I'm not quite sure of the best way to actually update that information. Maybe candidate.version.comments = @comments would work? Is it bad to add custom columns to paper_trail's table?

  2. Use paper_trail's metadata to store the comment. It doesn't seem like this was the intention for the metadata, but maybe it would work?

  3. Add another table as belongs_to :candidate that would keep track of the comments and version. This seems gross - would I also need to have this new table belong to the versions table?

Any insight would be much appreciated. I've been pretty focused on finding a solution with paper_trail since I've used it before but I'd also consider other gems or options that you've used in the past.

役に立ちましたか?

解決

I ended up going with option 1. I created a migration to add a comments field to the version table and added the following to CandidatesController#update

if @candidate.update(candidate_params)
    #Add comments if they are available
    @candidate.reload.versions.last.update(comments: params[:comments]) unless params[:comments].empty?

It seems to be working great but I'd appreciate any other thoughts that you have!

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top