If you want to jump to a file in vim it’s pretty easy to get there by placing your cursor over the file you want to teleport to and then hit the g+f keys.
What I didn’t know, is that you can easily go back to your previous file pressing CTRL+O.
Simple, yet so productive.
When iterating through a collection in a rails view, I typically use a block to do so right in my view.
If I need different id’s in the DOM for each element, it’s quickly achievable with the
with_index method which provides the index of each item as it iterates.
<!-- index.html.erb --> <ul> <% @products.each.with_index do |product, index| %> <li id="product<%= index %>"><%= product.name %></li> <% end %> </ul>
with_index works when you’re iterating through a collection within your view, you but how would you create different id’s in the DOM if you’re rendering your collection within a partial?
According to Local variables in Rails documentation, when you’re rendering a collection with a Rails partial, you can use a
counter as you iterate over that collection.
That same example rendering the collection with a rails partial would look like.
<!-- index.html.erb --> <ul> <% render partial: "product", collection: @products %> </ul> <!-- _product.html.erb --> <li id="product<%= product_counter %>"><%= product.name %></li>
While starting a new rails app, I noticed that I could simply skip installing
Test::Unit from the start. This left the initial application ready for Rspec to be installed and configured.
rails new my_app --skip-test
Pretty simple. Kicking myself for removing it manually each time I decided to use Rspec.
I wanted a quick and easy way to minify a CSS file for this site, without adding any fancy build tools like webpack, using a quick command.
The ideal workflow was:
After some digging and a node library, I came up with this.
npm install -g minify
:r !minify %
If you are looking to minify lots of files for an app there are clearly better options, but if you just want to shrink the size of a single file on a static site this is my new favorite.
When I am working on UI in a rails app, I typically don’t care to read the information in a rails debugger.
Running rails in the background is as easy as:
Quitting the process is slightly tricker than the good ol fashion cmd-c
I really enjoy using
ctrlp.vim for fuzzy finding files in vim. Makes navigation really easy.
ctrlp caches your directories upon first use for faster finding later on. That typically works great until you add or delete files, and your cache is no longer valid.
Fortunately, you can quickly purge your cache in ctrlp by clicking F5 once ctrlp is open.
I must have missed this line in the documentation.
A quick “search and replace in vim” google search will likely result in vim command looking something like this:
While useful, you may have a big file and want to restrict where you find and replace. The
% operator can be omitted to search a single line, or be replaced with a range of lines, like so:
I always wanted to love Jekyll as a blogging platform.
Unfortunately, creating awkwardly named markdown files and copying and pasting necissary front matter to the top of every text document was a shittier experience than simply clicking a “New post” button on some blogging CMS like WordPress or Ghost.