Add association User has many CodeHarborLink
- add migration tht associates User with CodeHarborLink - add belongs_to from CodeHarborLink to User - changed CodeHarborLinkController#index to only serve current user's CodeHarborLinks (leoselig/codeocean#2)
This commit is contained in:
@ -10,7 +10,7 @@ class CodeHarborLinksController < ApplicationController
|
|||||||
# GET /code_harbor_links
|
# GET /code_harbor_links
|
||||||
# GET /code_harbor_links.json
|
# GET /code_harbor_links.json
|
||||||
def index
|
def index
|
||||||
@code_harbor_links = CodeHarborLink.paginate(page: params[:page])
|
@code_harbor_links = CodeHarborLink.where(user_id: current_user.id).paginate(page: params[:page])
|
||||||
authorize!
|
authorize!
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -56,6 +56,7 @@ class CodeHarborLinksController < ApplicationController
|
|||||||
# Use callbacks to share common setup or constraints between actions.
|
# Use callbacks to share common setup or constraints between actions.
|
||||||
def set_code_harbor_link
|
def set_code_harbor_link
|
||||||
@code_harbor_link = CodeHarborLink.find(params[:id])
|
@code_harbor_link = CodeHarborLink.find(params[:id])
|
||||||
|
@code_harbor_link.user = current_user
|
||||||
authorize!
|
authorize!
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
class CodeHarborLink < ActiveRecord::Base
|
class CodeHarborLink < ActiveRecord::Base
|
||||||
validates :oauth2token, presence: true
|
validates :oauth2token, presence: true
|
||||||
|
validates :user_id, presence: true
|
||||||
|
|
||||||
|
belongs_to :user
|
||||||
|
|
||||||
def to_s
|
def to_s
|
||||||
oauth2token
|
oauth2token
|
||||||
|
@ -0,0 +1,5 @@
|
|||||||
|
class AddUserToCodeHarborLink < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
add_reference :code_harbor_links, :user, index: true, foreign_key: true
|
||||||
|
end
|
||||||
|
end
|
Reference in New Issue
Block a user