Skip to content

Commit

Permalink
Support older Rails versions
Browse files Browse the repository at this point in the history
  • Loading branch information
janko committed Nov 20, 2023
1 parent 9c91904 commit 117a85a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
4 changes: 2 additions & 2 deletions lib/rodauth/rails/feature/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ def before_rodauth
end

def rails_path_parameters
controller = [rails_controller.module_parent_name&.underscore, rails_controller.controller_name].compact.join("/")
controller = rails_controller.name.delete_suffix("Controller").underscore
route_method = self.class.route_hash.fetch(request.path.sub(/^#{prefix}/, ""))
action = route_method.to_s.sub(/^handle_/, "")
action = route_method.to_s.delete_prefix("handle_")

{ controller: controller, action: action }
end
Expand Down
8 changes: 3 additions & 5 deletions lib/rodauth/rails/routing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,14 @@ def rodauth(name = nil, as: name)
auth_class = Rodauth::Rails.app.rodauth!(name)
scope = auth_class.roda_class.new({})
rodauth = auth_class.new(scope)
controller = rodauth.rails_controller.name.delete_suffix("Controller").underscore

controller = rodauth.rails_controller.controller_name
namespace = rodauth.rails_controller.module_parent_name&.underscore

scope controller: controller, module: namespace, as: as, format: false do
scope controller: controller, as: as, format: false do
auth_class.route_hash.each do |route_path, route_method|
next if route_method.to_s.end_with?("_js")

path = "#{rodauth.prefix}/#{route_path}"
action = route_method.to_s.sub(/\Ahandle_/, "")
action = route_method.to_s.delete_prefix("handle_")
verbs = rodauth_verbs(rodauth, route_method)

match path, action: action, as: action, via: verbs
Expand Down

0 comments on commit 117a85a

Please sign in to comment.