tpope / vim-rails

rails.vim: Ruby on Rails power tools
http://www.vim.org/scripts/script.php?script_id=1567
4.1k stars 383 forks source link

Models in subfolders #510

Closed mahemoff closed 6 years ago

mahemoff commented 6 years ago

Is there a way to handle projects using the convention /app/models/blogs/blog.rb for models?

I've tried this for config/projections.json, but it still gives cannot find file "blog.rb" in path.

{
  "app/models/*/*.rb": {
    "command": "model",
    "affinity": "model",
    "alternate": "test/models/%s/%s_test.rb"
  }
}
tpope commented 6 years ago

Among other problems, your question says app/blogs but your code snippet says app/models.

mahemoff commented 6 years ago

The config is app/models because I'm trying to make it generic, since all models follow this convention, but not sure how to do it. (Updated the above from app/blog as you're right it should be app/models/blog).

The question is if there's a way to override the generic Rails convention of models all being in the same app/models folder, e.g. for a project using /app/models/blogs/blog.rb, app/models/posts/post.rb and so on, without having to configure a rule for each specific model type.

tpope commented 6 years ago

I don't understand the question. You can access a file at app/models/blog/blog.rb with :Emodel blog/blog. Are you trying to avoid typing blog twice? Because I don't think there is a way to achieve that, no.

mahemoff commented 6 years ago

Less typing would be nice but more importantly, navigation - so I could hit gf on Blog for example. Doing so causes the cannot find error.

tpope commented 6 years ago

You can fix gf by adjusting 'path' to include .../app/models/*. From memory, I think this would work:

{
  "*.rb": {"path": "app/models/*"}
}

Rails officially supported this convention a decade or so ago, but dropped it because it was way more trouble than it was worth. I'd encourage you to rethink as well.