Skip to content
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

ViewComponent related file #604

Open
natematykiewicz opened this issue Mar 6, 2024 · 1 comment
Open

ViewComponent related file #604

natematykiewicz opened this issue Mar 6, 2024 · 1 comment

Comments

@natematykiewicz
Copy link

natematykiewicz commented Mar 6, 2024

When using ViewComponent, you'll have a .rb file in app/components, and a corresponding Rails view whose path is the same except for the file extension.

For example:
app/components/foo_component.rb
app/components/foo_component.html.erb

Is there a good way to go to the Ruby file when I'm in the view, and go to the view when I'm in the Ruby file? :A and :R both bring me to spec/components/foo_component_spec.rb when in the Ruby file and do nothing ("No alternate file defined") when in the view.

Given how controllers and views work with :R, I think :R would be a good fit for this.

@natematykiewicz natematykiewicz changed the title ViewComponent alternate file ViewComponent related file Mar 6, 2024
@jbigler
Copy link

jbigler commented Jul 16, 2024

Create a .projections.json file in your project directory with the following content:

{
  "app/components/*_component.rb": {
    "type": "component",
    "related": "app/components/{}_component.html.erb"
  },
  "app/components/*_component.html.erb": {
    "type": "template",
    "related": "app/components/{}_component.rb"
  }
}

That will make :R work for moving between file and template. since we are already able to open the test with :A.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants