Vim autocomplete Rails model methods - ruby-on-rails-3

Is it possible to configure rubycomplete.vim that popup scope methods at the top and gather them from models files first, than from global declaration of ActiveRecord methods

If you are using tpopes awesome rails.vim in conjunction with exuberant ctags you can simply run the command :Rtags and it will generate all relevant tags for your project.

Related

Is there a way to use Sorbet without adding the # type annotation to every file?

I want to start using Sorbet for my Ruby on Rails project, but I've been asked not to add the type annotation to every file.
Is there a way to use Sorbet without adding the annotation?
Sorbet supports --typed-override feature where you can give sorbet a YAML file to specify what files should go into what level: https://github.com/sorbet/sorbet/tree/master/test/cli/override-typed.
srb runner doesn't currently know about it, but there has been chatter in the community about adding support for it: https://sorbet-ruby.slack.com/archives/CHN2L03NH/p1563404308018500
Note that from our experience at Stripe we found that having typed: true sigils in typed files has a lot of value as it allows users to build & verify their expectations on what is typed and what is not.

What's a good pattern for writing a Module and Class that augments Middleman?

I'm using Middleman 3.4.0 and in customizing my project I have some methods that are becoming too extensive for keeping them as helpers in config.rb. I'd like to write either a Module or Class and mix these back in as helpers with the ability to model the objects I need to work with. Is there a pattern for writing this as a Middleman extension somewhere that I can start from?
Use the middleman extension <extension name> command, which gives you a good boilerplate, see here.

Regenerate NSManagedObject subclasses on build

I have searched a bit but I cannot find an easy way to tell xcode to regenerate all the NSManagedObject subclasses on build. I would do this to be able to take all those classes off our git repository and only committing the model, and at the same time be sure that no one runs into problems because the classes are not in sync with the model
If you use something like mogenerator (http://rentzsch.github.com/mogenerator) to generate your model classes, you can get it to run as a script as per above suggestion.
This way, every time you trigger a build, the mogenerator script will run first making sure your classes have been updated according to the object model file.
Here's a good article to guide you through it http://www.esenciadev.com/2011/05/mogen-and-xcode4-integration/
You could add a run script.
Select your target and then select "Build Phases". From the "Add Build Phase" button in he lower right choose "Add Run Script".
No write a shell script, perhaps invoking an AppleScript or Automator script that instructs Xcode to generate the files. I have looked at the Dictionary of Xcode (Choose Xcode with "Open Dictionary" from the AppleScript Editor), and there are hooks select the entities in your data model. I did not see a way via AppleScript to generate the files, but you could have it choose the corresponding menu item.
This is quite a little project. Please share your code once you got it to work.
I wrote a script that generates NSManagedObject subclasses like Xcode does (classes and categories).
cdgenerator
It is very easy to use.

Using underscore.js with rails 3

I've been looking at underscore.js and wanted to add it to my rails project. I'm already using jQuery. Is there a best practice when it comes to using these two libraries together? Also, how do you deal with jQuery objects with underscore? Do you use jquery to select a bunch of elements, then run them through underscore?
You can either manually include the underscore js file in your assets, or you can use this gem:
https://github.com/rweng/underscore-rails
Underscore works well with Javascript collections and objects of any kind, so the functions do work well with jQuery objects.
I suggest you to use it without underscore-rails gem. It is very useless.
It produce nothing but new dependency for the project.
There is no reason to scare using the underscore.js directly.

Compiling Sass with custom variables per request under Rails 3.1

In a Rails 3.1 app, one controller needs to have all its views compile whatever Sass stylesheets they might need per request using a set of custom variables. Ideally, the compilation must happen via the asset pipeline so that content-based asset names (ones that include an MD5 hash of the content) are generated. It is important for the solution to use pure Sass capabilities as opposed to resorting to, for example, ERB processing of Sass stylesheets.
From the research I've done here and elsewhere, the following seems like a possible approach:
Set up variable access
Create some type of variable accessor bridge using custom Sass functions, e.g., as described by Konstantin Haase here (gist). This seems pretty easy to do.
Configure all variable access via a Sass partial, e.g., in _base.sass which is the Compass way. The partial can use the custom functions defined above. Also easy.
Capture all asset references
Decorate the asset_path method of the view object. I have this working well.
Resolve references using a custom subclass of Sprockets::Environment. This is also working well.
Force asset recompilation, regardless of file modification times
I have not found a good solution for this yet.
I've seen examples of kicking off Sass processing manually by instantiating a new Sass::Engine and passing custom data that will be available in Sass::Script::Functions::EvaluationContext. The problem with this approach is that I'd have to manage file naming and paths myself and I'd always run the risk of possible deviation from what Sprockets does.
I wasn't able to find any examples of forcing Sprockets processing on a per-request basis, regardless of file mod times, that also allows for custom variable passing.
I'd appreciate comments on the general approach as well as any specific pointers/suggestions on how to best handle (3).
Sim.
It is possible. Look here SASS: Set variable at compile time
I wrote a solution to address it, I'll post soon and push it here, in case you or someone else still need it.
SASS is designed to be pre-compiled to CSS. Having Sprockets do this for every request for a view on a per request basis is not going to perform very well. Every request is going to have to wait for the compilation to be done, and it is not fast (from a serving-pages point of view).
The MD5 generation is within Sprockets, so if you are changing custom variables you are going to have to force a compilation on every single request to make sure that changes are seen because the view is (probably) not going to know.
It sounds as though this is not really in the sweet-spot of the asset-pipeline, and you should look at doing something more optimised for truly dynamic CSS.
Sorry. :-)