rails.vim and custom controllers location - ruby-on-rails

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

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

Related

Where can I find the default templates for all the Grails fields plugin types?

I was hopping to have an easy way to customize the display behavior of the Grails fields plugin after reading its docs, but I just realized that it demands an enormous effort as there is no available templates to start from.
I can see the display functionality is hard-coded in FormFieldsTagLib (from methods like renderDefaultInput() ) but I think it is imperative to have the templates themselves (or a way to generate them, somewhat like generating static scaffolding in Grails).
I can see no consistent (and reasonable) way to customize display behaviors for the Grails fields plugin without that. Am I missing something?
Imagine the use case where someone wants to change the boolean default rendering just to display the field label after (and not before) the checkbox, and keep it available to all the boolean fields within its application. Which concerns will he need to handle regarding if the field is required, has errors, prefix and so on? When all he needed was just moving two divs around.
Grails version: 2.5.4, fields-plugin version: 1.5.1
You aren't missing something. You'd have to re-create the existing implementation of each field type rendering in a template for use with the plugin. There isn't a way to generate a file to start with (like scaffolding).
I won't bore you with the historical reason as to why this is the case, but if you do create a set of base templates it would be a good idea to contribute back to the plugin.
I had an issue with the <f:table> tag, and found this post, which led me to find the base or default template inside the plugin repo.
Take a look at
https://github.com/grails3-plugins/fields/tree/master/grails-app/views
That may help you finding some default templates, along with the official doc and this answer on where to put the override.
Hope it helps you.

Migrating to Vim from RubyMine - Interpreted Auto completion

Up until last week, I had been using RubyMine for my Rails development. I know it has a vim plugin but I have been working on migrating my development to vim and tmux. I don't want to keep using the mouse and VIM gives me a lot more flexibility. I have found plugins and workarounds for almost all the features I care about except the "interpreted auto complete" functionality in my first screenshot below. RubyMine interprets the whole rails application and offers sorted-by-relevance suggestions (as you can see, it's showing me instance variables and methods for the class in question and the modules it includes) THEN it shows (less relevant) methods available on the Object class. It also shows the method signature when there's one.
Also, in my second screenshot, you can see how RubyMine offers autocompletion for core Ruby classes.
Compare this to the bottommost screenshot. I do have completion but there's no way to find what I'm looking for. I'm using ctags , YouCompleteMe, vim-rails, vim-ruby and I also tried installing eclim to see if it makes a difference.
Is there a plugin I've missed that can enhance my auto completion? It doesn't look like RubyMine is doing something super crazy. pry can give me the same 'power' if it were running in the same 'context'.
First Screenshot (RubyMine interpreted auto complete):
Second Screenshot (RubyMine core Ruby classes auto complete):
Third Screenshot (vim omnifunc + ctags):
Important Note
This solution only works for Ruby 1.9+
I forked 'vim-ruby' at https://github.com/zxiest/vim-ruby and modified it as such:
Method signatures now appear in completion.
I disabled sorting by name for methods.
Plugins and Settings
vim-rails
I'm using vim-rails https://github.com/tpope/vim-rails
supertab
I'm using supertab https://github.com/ervandew/supertab instead of YouCompleteMe (mentioned in my question) although YouCompleteMe is super fast and automatic but there are currently some compatibility issues between my it and my vim-ruby fork.
vim-easytags
I'm using vim-easytags https://github.com/xolox/vim-easytags
Add this to your ~/.vimrc
:set tags=./tags;
:let g:easytags_dynamic_files = 1
Make sure to touch ./tags in your project directory.
Issue :UpdateTags -R **/*.* from vim in order for easytags to generate your tags file.
Remap omnicomplete
In order for omnicomplete to pop up, by default, we have to hit <C-X><C-O>. I remapped this to <C-Space> by inserting the following in my ~/.vimrc:
inoremap <C-#> <C-x><C-o>
I now press tab when I want supertab to complete my code and Ctrl+Space when I want omnicomplete to trigger and show method signatures for me. There's definitely a better way to integrate this (i.e. getting supertab to call omnicomplete after a dot)
And here goes the screenshot! Notice that method sorting being off allowed my custom resize method to appear on top and the signatures now appear in the completion (as well as in the editor when enter is pressed!)

in orchard why does manually adding entries to the database not work?

I am using the Advanced Menu for Orchard, I have alot of duplicated content to add to multiple menus so was trying to do this directly into the database.
The problem I had was when I add items to the database the items don't show up and the CMS breaks and doesn't allow items to be added (this causes a duplicate primary key error).
Can anyone tell me why this is, and what I would need to do if I wanted to add entries manually?
Not knowing how you've tried to add them, it's hard to say. Maybe you've created part records without content item records, making them orphans? But again, I'm just guessing, as I have no idea what you tried to do.
For manual entries you might be better off using the command line utility. see http://www.orchardproject.net/docs/Using-the-command-line-interface.ashx
Or the import/export functionality (which I think just runs the command line stuff)
If yo want to know more follow piotr's blog. It's full of great stuff!
http://www.szmyd.com.pl/

osCommerce - adding tools for admin

Is there a way to add a tool to osCommerce without having to edit any file? Just simply place files in some dir maybe?
I need to write addon for administrator of osC that lets them print something for every order.
No there isn't.
If you want to extend the admin of osCommerce, you'll have to get dirty and edit some lines of code for the existing files.
This is separate to things like the payment and shipping modules where you can just drop in some files and have it available for install.

Is there a tool that allows to edit related code in single file?

My idea is that it's much easier to edit related code when it sits in single "work" file. E.g. in Rails application when you implementing some functionality you may edit 1 function per file in the following files: integration test, controller test, controller, model, controller helper. So if it would be possible to 1) mark this code fragments 2) automatically collect them in "work" file 3) edit them togather 4) the tool synchronizes (puts back) the changes; it could simplify development process in many cases. Especially if you need to go through many tweek-and-try iterations.
Vim works fine for this. Install the Rails.vim(1) plugin and with the command :AV you can open a vertical split with the accompanied tests/specs, or :RV to open related files like migrations and views (depending on whether you're viewing model or controller). When you're workspace becomes to cluttered, use :only to go back to one file. Splits are the best way to manage multiple related files IMHO. You can even open the same file twice to see two parts of the same file. It's not exactly the same as you are describing, but it comes close.
1: http://rails.vim.tpope.net/
Just open up Vim and open some windows. What's the problem?

Resources