Is there a tool that allows to edit related code in single file? - ruby-on-rails

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?

Related

Handler for missing #include virtual links

We have to maintain a lot of classic ASP and VB/ASP.Net applications that link to many different parts of a static website.
The master pages are littered with various
<!-- #include virtual="/site/footer.something" -->
and similar, where there are many many combinations of what /site/ can be.
The problem is, when you're debugging etc. when you try to run one of these sites locally, you're almost guaranteed to get a parser error.
What I want to do is come up with a generic handler so that I can just insert a blank file for any #include file that doesn't exist.
I tried to setup a URL Rewrite rule, which works in the browser (just redirects to an empty html file) but I'm guessing the ASP parser doesn't include as a webrequest as it still generates a parser error.
I don't want to have to copy the static content to my workstation everytime I open a new app and I don't want to edit the master pages to exclude the links as one day I'm just going to forget and deploy something broken.
So the question is, is there a way to serve a default file for these declarations, or some other method ?
Edit: To consider a different fix to this problem; is there some way to insert some kind of file-system handler that can pick up requests for missing files in specific locations and return predefined content ?
Yeah, I know that's a really offbeat direction and probably a very bad idea in practise, but this is quite a frustrating problem in the office now.
What's irritating is that even though IIS has SSI disabled, the ASP processer still honours #include directives. Is there a way to either disable that, or perhaps some way to override the behaviour in some kind of generated class ?
The problem you will encounter is that includes are processed before any of your code runs. The server gathers all of the resources referenced in the scripts then compiles and runs your code. By the time your code is running, the missing include has already thrown a compiler error.
Further, what you're asking could potentially run into other problems. Often times includes contain code (procedures, constants, variable declarations, etc.) that other scripts rely on. So, even if you were to replace the missing include with an empty file, you still may encounter other parser errors if the including script expects that include to contain specific code.
Probably your best bet is to make a console app or something similar that parses your files looking for the include statements, resolves the relative path based on your directory structure and does what you want - write an empty file if it doesn't exist. You could then run your projects through this parser and at least eliminate that issue.
Additionally, you mention the possibility of accidentally deploying something that you've edited to circumvent this problem. I would assume then, that if you were to write out these "dummy" includes, there is no possibility of you accidentally deploying them and overwriting good files?

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
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

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/

One action reused in multiple applications

I have a symfony application with two different applications (frontend, backend) but there is one action in common. Now I have duplicated its code in both apps but I don't like that at all.
Is there a way to reuse an action in multiple symfony applications?
The easiest way would be to make an actions base class in lib with the shared methods/actions. Then the modules that need to use this functionality can just extend that base class instead of sfActions.
You could also probably just use an event listener on method_not_found of sfComponent. But that may not work as expected if the method is an actual action (and it would also be available in all modules and all components without some special detection logic).
The most complicated way would be to make a Plugin. Of course that would require making the logic that works with any models dynamic so it can be configured or isolating the relevant parts of the schema to the plugin's schema.
Two more options:
1) if your are on Linux, make a symlink to your actions.class.php or even whole module, if you share the same templates.
cd apps/backend/modules/name
ln -s ../../frontend/modules/name name
2) if you have not gone too far in development, re-factor your project to have only ONE application (my favourite).
If you want to share a module (and hence also it's actions), the proper way is to create a plugin.

ASP.NET MVC - Intellisense doesn't update model

Firstly, I've done a build, I've done a clean, I've done a rebuild, of both the project and the solution, so that's not the problem.
When I change my model for some reason the intellisense (in fact, it's not just the intellisense as if I do a build it comes up with an error as well) doesn't work. I have a model under ViewData.Model.ContractCostCentre which exists. VS isn't picking this up, at all. Instead, it's referring to an old one which has since been deleted and replaced with the prior one, this is called ViewData.Model.ContractCCList. So in my view I'm having to iterate over a ViewData.Model.ContractCCList despite this not even existing in my *.dbml file.
This isn't the first time I've had this problem, it seems to happen quite often if I change my dbml file (and it's likely to change as we work on highly progressive systems which are always subject to change).
Any ideas?
can you look into your ????.designer.vb or .cs, depend which language you are using
if you don't see that file, show all file in solution
intellisense is using that file
Kezzer,
At the top of your View, there is part of a line of code that determines what model type the page uses. It should look something like this (my example is in c#):
Inherits="System.Web.Mvc.ViewPage<ViewData.Model.ContractCCList>"
Change it to look like this:
Inherits="System.Web.Mvc.ViewPage<ViewData.Model.ContractCostCentre>"

Resources