Skip to content

Instantly share code, notes, and snippets.

@Melrt
Last active April 3, 2024 12:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Melrt/f88102501119c8f246d245b0853f13ec to your computer and use it in GitHub Desktop.
Save Melrt/f88102501119c8f246d245b0853f13ec to your computer and use it in GitHub Desktop.
# app/controllers/subscriptions/application_controller.rb
class Subscriptions::ApplicationController < ApplicationController
def steps_provider
# current_step est défini dans chaque controller
@steps_provider ||= StepsProvider.new(@subscription, current_step)
end
helper_method(:steps_provider)
def subscription_steps
steps_provider.steps
end
helper_method(:subscription_steps)
end
# app/steps/base_step.rb
class BaseStep
include Rails.application.routes.url_helpers
attr_reader :name
def initialize(subscription, name)
@subscription = subscription
@name = name
end
def link
# Route de l'étape
"#"
end
def visible?
true
end
def completed?
# Définir la logique pour vérifier si l'étape est complétée, ou mieux, mettre la policy associée à l'étape
false
end
end
<!-- app/views/subscriptions/partials/_breadcrumb.html.erb -->
<% subscription_steps.each do |step| %>
<li>
<% if step.completed? %>
<%= inline_svg_tag("subscriptions/breadcrumb/valid_or_current_step.svg") %>
<%= link_to(
t(".#{step.name}"),
step.link,
class: class_names(
"fw-bold" => step.name == steps_provider.current_step.name
)
) %>
<% else %>
<%= inline_svg_tag("subscriptions/breadcrumb/step_to_complete.svg") %>
<span><%= t(".#{step.name}") %></span>
<% end %>
</li>
<% end %>
# app/providers/steps_provider.rb
class StepsProvider
def initialize(subscription, current_step_name)
@subscription = subscription
@current_step_name = current_step_name
end
def steps
@__steps ||= steps_list.select(&:visible?)
end
private
def steps_list
[
UserDetailsStep.new(@subscription, :user_details_step),
# Ajoutez d'autres étapes ici en suivant le modèle ci-dessus
]
end
end
# app/steps/user_information_step.rb
class UserDetailsStep < BaseStep
def step_link
edit_subscriptions_user_details_path(@subscription)
end
def completed?
@subscription.user.extend(UsersDetailsValidation).valid?
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment