Step 1 把 user_id 加入到 job table

rails g migration add_user_id_to_job 
db/migrate/20170501154915adduseridtojob.rb
def change
    add_column :jobs, :user_id, :integer      
end
rake db:migrate 

Step 2 建立收藏功能的 Model

rails g model collect job_id:integer user_id:integer  

Step 3 新建 join 和 quit method

app/controllers/jobs-controller.rb
before_action :authenticate_user!, only: [:new, :create, :edit, :update, :destroy, :join_collect, :quit_collect]
  
def join  
  @job = Job.find(params[:id])

  if !current_user.is_member_of?(@job)
    current_user.join_collect!(@job)
  end

  redirect_to job_path(@job)
end

def quit
  @job = Job.find(params[:id])

  if current_user.is_member_of?(@job)
    current_user.quit_collect!(@job)  
  end

  redirect_to job_path(@job)
end  

Step 4 修改 config/routes

config/routes.rb
resources :jobs do
    member do
      post :join
      post :quit
    end
end 

产生路径

join_job POST   /jobs/:id/join(.:format)                       jobs#join
quit_job POST   /jobs/:id/quit(.:format)                       jobs#quit

Step 5 建立 model 之间的关系

app/models/collect.rb
belongs_to :job
belongs_to :user
app/models/job.rb
has_many :collects 
has_many :members, through: :collects, source: :user
app/models/user.rb
has_many :jobs
has_many :collects
has_many :participated_jobs, :through => :collects, :source => :job

def is_member_of?(job)             # user 使用的判断式  

  participated_jobs.include?(job)  # 是否已经收藏过这项工作  

end

def join_collect!(job)
  participated_jobs << job
end

def quit_collect!(job)
  participated_jobs.delete(job)
end