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

[750] Un-refactor edit action a bit #755

Merged
merged 1 commit into from
Mar 16, 2021
Merged
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
20 changes: 11 additions & 9 deletions app/controllers/orders_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,13 @@ def create

def edit
@order = Order.includes(order_details: :item).find(params[:id])
determine_edit_view
if current_user.can_edit_order?(@order)
render_status_or_edit
elsif current_user.can_view_order?(@order)
render :show
else
redirect_to orders_path
end
end

def update
Expand All @@ -45,15 +51,11 @@ def update

private

def determine_edit_view
if current_user.can_edit_order?(@order)
if Rails.root.join("app/views/orders/status/#{@order.status}.html.erb").exist?
render "orders/status/#{@order.status}"
end
elsif current_user.can_view_order?(@order)
render :show
def render_status_or_edit
if Rails.root.join("app/views/orders/status/#{@order.status}.html.erb").exist?
render "orders/status/#{@order.status}"
else
redirect_to orders_path
render :edit
end
end
end