Last active
May 17, 2025 04:58
-
Star
(285)
You must be signed in to star a gist -
Fork
(36)
You must be signed in to fork a gist
Revisions
-
dhh revised this gist
Apr 16, 2014 . 1 changed file with 6 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,10 +1,12 @@ # config/routes.rb resources :documents do scope module: 'documents' do resources :versions do post :restore, on: :member end resource :lock end end -
dhh revised this gist
Apr 7, 2014 . 1 changed file with 0 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -35,8 +35,6 @@ module Documents class LocksController < ApplicationController include DocumentScoped, ProjectScoped def update @document.lock!(current_person) end -
dhh revised this gist
Apr 7, 2014 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -17,7 +17,7 @@ def index end def show @document = @project.documents.find(params[:id]) end def new @@ -81,6 +81,6 @@ module DocumentScoped private def set_document @document = @project.documents.find(params[:document_id]) end end -
dhh revised this gist
Apr 7, 2014 . 1 changed file with 10 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,13 @@ # config/routes.rb resources :documents do resources :versions, controller: "documents/versions" do post :restore, on: :member end resource :lock, controller: "documents/locks" end # app/controllers/documents_controller.rb class DocumentsController < ApplicationController include ProjectScoped -
dhh revised this gist
Apr 7, 2014 . 1 changed file with 22 additions and 10 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,7 @@ # app/controllers/documents_controller.rb class DocumentsController < ApplicationController include ProjectScoped def index @documents = @project.documents end @@ -21,6 +23,8 @@ def create # app/controllers/documents/locks_controller.rb module Documents class LocksController < ApplicationController include DocumentScoped, ProjectScoped before_action :set_document def update @@ -30,19 +34,16 @@ def update def destroy @document.unlock!(current_person) end end end # app/controllers/documents/versions_controller.rb module Documents class VersionsController < ApplicationController include DocumentScoped, ProjectScoped before_action :set_version def show end @@ -53,12 +54,23 @@ def restore private def set_version @version = @document.versions.find(params[:id]) end end end # app/controllers/concerns/document_scoped.rb module DocumentScoped extend ActiveSupport::Concern included do before_action :set_document end private def set_document @document = @project.documents.trashed_or_not.find_by_id(params[:document_id]) end end -
dhh created this gist
Apr 7, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,64 @@ # app/controllers/documents_controller.rb class DocumentsController < ApplicationController def index @documents = @project.documents end def show @document = @project.documents.trashed_or_not.find_by_id(params[:id]) end def new @document = Document.new end def create @document = @project.documents.create! document_params.merge(creator: current_person) end end # app/controllers/documents/locks_controller.rb module Documents class LocksController < ApplicationController before_action :set_document def update @document.lock!(current_person) end def destroy @document.unlock!(current_person) end private def set_document @document = @project.documents.trashed_or_not.find(params[:document_id]) end end end # app/controllers/documents/versions_controller.rb module Documents class VersionsController < ApplicationController before_action :set_document, :set_version def show end def restore @document.restore!(@version) end private def set_document @document = @project.documents.trashed_or_not.find_by_id(params[:document_id]) end def set_version @version = @document.versions.find(params[:id]) end end end