-
Notifications
You must be signed in to change notification settings - Fork 31
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
Make application routes usable on example views #141
base: master
Are you sure you want to change the base?
Make application routes usable on example views #141
Conversation
I'm currently reading an article and some documentation to be sure of my proposal. |
Pull Request Test Coverage Report for Build 815
💛 - Coveralls |
Proposal 2diff --git a/config/routes.rb b/config/routes.rb
index 7293246..cfa10cc 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -1,5 +1,5 @@
# frozen_string_literal: true
Komponent::Engine.routes.draw do
- resources :styleguide, only: %i[index show]
+ resources :styleguide, only: %i[index show], module: :komponent
end
diff --git a/lib/generators/komponent/templates/styleguide/components/sidebar/_komponent_sidebar.html.erb b/lib/generators/komponent/templates/styleguide/components/sidebar/_komponent_sidebar.html.erb
index 195ade3..f6198a5 100644
--- a/lib/generators/komponent/templates/styleguide/components/sidebar/_komponent_sidebar.html.erb
+++ b/lib/generators/komponent/templates/styleguide/components/sidebar/_komponent_sidebar.html.erb
@@ -3,7 +3,7 @@
<ul class="komponent-sidebar-items">
<%- components.each do |_k, component| %>
<li class="komponent-sidebar-item">
- <%= link_to_unless_current component.title, styleguide_path(id: component.id) %>
+ <%= link_to_unless_current component.title, komponent.styleguide_path(id: component.id) %>
</li>
<% end %>
</ul>
diff --git a/lib/komponent/engine.rb b/lib/komponent/engine.rb
index 477160c..41c40da 100644
--- a/lib/komponent/engine.rb
+++ b/lib/komponent/engine.rb
@@ -9,7 +9,7 @@ require 'komponent/translation'
module Komponent
class Engine < Rails::Engine
- isolate_namespace Komponent
+ engine_name "komponent"
rake_tasks do
load 'komponent/rails/tasks/komponent.rake' |
Since we don't have helper in I don't think we really needs to isolate our engine. |
@@ -5,6 +5,8 @@ class StyleguideController < ::ApplicationController | |||
layout 'komponent' | |||
rescue_from ActionView::MissingTemplate, with: :missing_template | |||
|
|||
include Rails.application.routes.url_helpers |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure for this. For me this is not a clean way.
I agree. Can you implement solution #2 in your PR? |
I'll try to found some time in the next days to rework on this. |
ec33e78
to
abe305b
Compare
I updated the code to implement proposal 2 |
NB: We will need to inform users that they need to replace |
Done |
If we want to have a component that works directly with a model object, Rails application returns an error.
With the following example.
We have the following error:
Explanation
The
komponent
gem is isolated so application routes are not available fromKomponent::StyleguideController
.Proposal 1
The changes I did expose Rails application routes in
Komponent::StyleguideController
. And I named the engine to be able to access komponent application routes.Proposal 2 (current code state of this PR)
Stop to isolate the engine. So routes are loaded in application. But helper will be loaded too.