I want to auto generate a hash value from within the model.
The user creates a resume, they then have the option to share it by clicking a share button which auto generates a unique (random hashed string) url tied to that specific resumes view.
class ResumesController < ApplicationController
def share
@resume = Resume.find(params[:id])
@share = Share.new
@share.resume_id = @resume.id
@share.save
redirect_to action: 'index'
end
end
My Share model has two columns, resume_id, which I already set in the controller, and
hash_url` which I want to automatically set in the model.
class Share < ActiveRecord::Base
attr_accessible :label, :resume_id, :url
end
My question is, how do I go about creating a unique hash and store it in the hash_url
column? Also, I'm assuming before it saves it will have to check the share table to make sure it is not saving a hash that already exists.