Skip to content

Fix inertia helper for namespaced routes #201

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

Merged
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
4 changes: 1 addition & 3 deletions lib/patches/mapper.rb
Original file line number Diff line number Diff line change
@@ -3,9 +3,7 @@ module InertiaMapper
def inertia(*args, **options)
path = args.any? ? args.first : options
route, component = extract_route_and_component(path)
scope module: nil do
get(route, to: 'inertia_rails/static#static', defaults: { component: component }, **options)
end
get(route, to: StaticController.action(:static), defaults: { component: component }, **options)
end

private
3 changes: 3 additions & 0 deletions spec/dummy/config/routes.rb
Original file line number Diff line number Diff line change
@@ -54,6 +54,9 @@
scope :scoped, as: "scoped" do
inertia 'inertia_route' => 'TestComponent'
end
namespace :namespaced do
inertia 'inertia_route' => 'TestComponent'
end
resources :items do
inertia inertia_route: 'TestComponent', on: :member
inertia :inertia_route_with_default_component
6 changes: 6 additions & 0 deletions spec/inertia/rendering_spec.rb
Original file line number Diff line number Diff line change
@@ -76,6 +76,12 @@
it { is_expected.to include inertia_div(page) }
end

context 'via a namespaced inertia route' do
before { get namespaced_inertia_route_path }

it { is_expected.to include inertia_div(page) }
end

context 'with a default component' do
let(:page) { InertiaRails::Renderer.new('inertia_route_with_default_component', controller, request, response, '').send(:page) }