Replies: 7 comments
-
In a Rails app, I personally like to organise views based on the resources they represent. For example, if I have an Articles resource, I’d have That said, the way you organise your views is a personal choice. You can use the same generators with |
Beta Was this translation helpful? Give feedback.
-
Speaking only for myself, I actually think it's liberating to think of Phlex components as not tied to controllers at all, and I go further and consider Phlex page views templates and not controller actions either. Sometimes page templates can be very similar across different models. In my case news_items#show and research_projects#show would look more or less identical and could really be one Phlex view (page) ( |
Beta Was this translation helpful? Give feedback.
-
Yeah, makes sense. |
Beta Was this translation helpful? Give feedback.
-
Sorry for piggybacking off this discussion, but I would like to add a small point that is kind of bothering me: I agree to most of what was written above, but if I see this correctly, current defaults in Do not get me wrong, I am totally in favor of using modules as namespaces in ruby as much as possible. And I sometimes regret that rails did not do that properly from day one. But since it did not, I believe rails developers have come to expect that classes in a direct subfolder of So I think I would prefer that (as a default) As a side-effect, this would mean that we could replace config.autoload_paths << "#{root}/app" in config.autoload_paths << "#{root}/app/views" which is a lot narrower. The former worries me a bit because of its broad nature. I have not come across an actual conflict yet, but at the very least it introduces some ambiguity (does |
Beta Was this translation helpful? Give feedback.
-
I'm kind of erring on the side of appending This completely removes conflicts and make it very clear what a class is. It also has the added benefit of being able to differentiate between components and views...
This is currently my preferred approach, as it feels much more Rails-like. |
Beta Was this translation helpful? Give feedback.
-
I'm trying the following approach in my side project (https://github.com/stephannv/stefin):
So I have |
Beta Was this translation helpful? Give feedback.
-
It's great that you can organise views however you want — and maybe we should introduce some configuration for the Namespacing views under a Rails has traditionally put the type of object at the end of the name for everything apart from models — e.g. ArticlesController, PublishArticleJob, etc. I don’t think this is a great pattern. I would change Rails to namespace I recognise namespacing goes against the established pattern, but I think there's quite a big difference: controllers rarely reference other controllers and jobs seldom reference other jobs, but views reference different views all the time. I think this is where Ruby’s relative constant lookup can be really useful. If I’m in the |
Beta Was this translation helpful? Give feedback.
-
From official docs:
Yeah, but what do you think about suggest organizing the phlex objects into 2 folders (pages and components)?
This can be done inside
app/views
folder:app/views/components
app/views/pages
Or using
app
folder:app/components
app/pages
Pages represents the application views, the html response from controllers, the
PostsController#index
renderspages/posts/index.rb
. Pages usually represents a route and are rarely reused but can take all other advantages from Phlex framework. We could create a ApplicationPage to setup some shared behavior (eg. metatags).Components are what makes up the different parts of your page and can be reused and imported into your pages, layouts and even other components.
They are the same, but they are different.
It is already possible to organize things the way I wrote, but what do you think of this as a good practice recommendation in the docs.
Beta Was this translation helpful? Give feedback.
All reactions