Assignments working

This commit is contained in:
Jorge Manrubia
2025-05-06 06:42:26 +02:00
parent 65d809dd8d
commit 72ffcfac8b
7 changed files with 107 additions and 14 deletions
+28
View File
@@ -0,0 +1,28 @@
class Command::Parser::Context
attr_reader :user, :url
def initialize(user, url:)
@user = user
@url = url
end
def cards
route = Rails.application.routes.recognize_path(url)
controller = route[:controller]
action = route[:action]
params = route.except(:controller, :action)
cards_from(controller, action, params)
end
private
def cards_from(controller, action, params)
if controller == "cards" && action == "show"
user.accessible_cards.where id: params[:id]
elsif controller == "cards" && action == "index"
filter = user.filters.from_params params.reverse_merge(**FilterScoped::DEFAULT_PARAMS)
filter.cards
end
end
end