-
I'm looking for a way to quickly jump between view component files (template and Ruby) in VS Code. For example, if you're in the template, running a command would open the related Ruby file. Has anyone found a good way to do this? I'm considering creating an extension for this but thought I'd ask here first to ensure no one else has done this. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
I don't believe such a thing exists at the moment! It'd be a good idea to clone Rails Go To Spec and rework it in a similar way, though there are a few different ways templates can exist alongside component code that this would hopefully accommodate. |
Beta Was this translation helpful? Give feedback.
-
I personally use the will-wow.vscode-alternate-file extension. Here is my {
"app/components/**/*.html.erb": {
"alternate": "app/components/{}.rb"
},
"app/components/**/*.rb": {
"alternate": "app/components/{}.html.erb"
},
"app/*.rb": { "alternate": "test/{}_test.rb" },
"lib/*.rb": { "alternate": "test/lib/{}_test.rb" }
}
Since no key bindings are set by default I created one ( [
{ "key": "cmd+shift+a", "command": "alternate.alternateFileInSplit", "when": "editorTextFocus" }
] The alternate files also works for switching between I also created a VS Code / Chrome extension to let you quickly open a partial / view component directly from Chrome in VS Code by right clicking on it and selecting it from the partial hierarchy. The Rails.application.configure do
# Annotate rendered view with file names.
config.action_view.annotate_rendered_view_with_filenames = true
end Hope that helps. |
Beta Was this translation helpful? Give feedback.
I personally use the will-wow.vscode-alternate-file extension. Here is my
.projections.json
file:Since no key bindings are set by default I created one (
cmd+shift+a
) to alternate between the view component and the HTML (Preferences: Open Keyboard Shortcuts (JSON)
in th…