Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rails.vim and custom controllers location

I love Rails.vim but I have a problem with using it in some projects. I have two places for controllers in one of my apps:

app/controllers
app/controllers/v1/api

Can I configure (perhaps in config/rails.vim?) this extra path somehow? I'd like to use both of them.

I can navigate by hand like this:

:Rcontroller v1/api/messages_controller.rb

but :Rmodel from this controller does not work, it tries to jump to models/v1/api/model.rb

like image 654
Nazgob Avatar asked Dec 04 '11 20:12

Nazgob


1 Answers

This isn't tied into the rails.vim add-on, but you can add an additional command to do this for you. I believe this would be far easier than trying to modify the rails.vim source.

I actually wrote a blog post about something similar. For your purposes, you'd want to put something like this in your vimrc:

command -nargs=? RcontrollerApi e \path\to\your\project\app\controllers\v1\api\<args>_controller.rb

You could then call it like this:

:RcontrollerApi messages

You wouldn't have the extra rails.vim sweetness that goes along with the native functionality, though (Like typing :Rcontroller in a view to automatically go to that file).

Here's an idea that may (or may not) work. I don't believe it will allow you to access the aforementioned functionality but it very well may point you in the right direction.

command -nargs=? RcontrollerApi Rcontroller v1/api/<args>_controller.rb
like image 176
Chuck Callebs Avatar answered Sep 20 '22 23:09

Chuck Callebs