Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#238] Add duplicate story button #240

Merged
merged 2 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion app/controllers/adventures_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class AdventuresController < ApplicationController
before_action :set_adventure, only: [:show, :edit, :update, :destroy, :details, :source, :offline, :authenticate]
before_action :set_adventure, only: [:show, :edit, :update, :destroy, :details, :source, :offline, :authenticate, :duplicate]
before_action :check_authentication, only: [:show]

def index
Expand Down Expand Up @@ -132,6 +132,19 @@ def csv
end
end

def duplicate
if [email protected]_by?(current_user)
flash[:alert] = "You can't modify that Adventure"
return redirect_to root_url
end

duplicated_adventure = @adventure.dup
duplicated_adventure.title = "Copy of #{@adventure.title}"
duplicated_adventure.save

redirect_to [:edit, duplicated_adventure]
end

private

def set_adventure
Expand Down
2 changes: 2 additions & 0 deletions app/views/adventures/details.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

<%= render "shared/adventure_form", is_update: true, correct_user: @adventure.user && @adventure.user == current_user %>

<%= link_to "Duplicate Story", duplicate_adventure_path(@adventure), method: :post, class: "SlantButton" %>

<footer class="AccountFormFooter">
<%= link_to 'Back to Edit', [:edit, @adventure] %>
<br>
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
get "source", on: :member
get "offline", on: :member
post "authenticate", on: :member
post "duplicate", on: :member
get "mine", on: :collection, as: :my
get "archived", on: :collection, as: :my_archived
get "csv", on: :collection
Expand Down
Loading