Ruby on Rails Extending rails.vim Navigation Commands with projectionist.vim One of my favorite Vim plugins is rails.vim by Tim Pope. And the reason it's one of my favorite Vim plugins is all of the navigation commands that it gives you for working with Ruby on Rails projects. So, rather than having to
Ruby on Rails Webcal Links in Rails with the icalendar Gem The icalendar gem is a useful way to generate iCalendar files for use with various calendar applications. One thing I couldn't find good documentation on, though, is how to use it to create a Webcal link in a Ruby on Rails app, so I
Ruby on Rails Greatest-Per-Group Query in Rails Using a View Backed Model This is part 4 of 4 in a series on how to use Greatest Per Group queries in Ruby on Rails to avoid the N + 1 query problem: When and how to use Greatest Per Group queries (with PostgreSQL) Rails implementation using custom query
Ruby on Rails Greatest-Per-Group Query in Rails Using a Scoped has_one Assocation This is part 3 of 4 in a series on how to use Greatest Per Group queries in Ruby on Rails to avoid the N + 1 query problem: When and how to use Greatest Per Group queries (with PostgreSQL) Rails implementation using custom query
Ruby on Rails Greatest-Per-Group Query in Rails Using Custom Query Methods This is part 2 of 4 in a series on how to use Greatest Per Group queries in Ruby on Rails to avoid the N + 1 query problem: When and how to use Greatest Per Group queries (with PostgreSQL) Rails implementation using custom query
Ruby on Rails Greatest-Per-Group Query in PostgreSQL Using DISTINCT ON This is part 1 of 4 in a series on how to use Greatest Per Group queries in Ruby on Rails to avoid the N + 1 query problem: When and how to use Greatest Per Group queries (with PostgreSQL) Rails implementation using custom query
Ruby on Rails Rails: Static Pages Using the Controller Route Macro One of my Rails apps recently took responsibility for serving the home page and marketing pages from an installation of Wordpress, mainly to allow for a site-wide nav bar which shows login status. Doing this in Rails is not rocket science, but after experimenting
Ruby on Rails Rails: Organizing Controllers with Modules One of my Ruby on Rails apps has lots of models and a few models that each have lots of has_many associations. For instance, the Company model has 27 has_many associations. Naturally, I have routes and controllers for most of these associations,
Ruby on Rails Rails: Organizing Models by Attribute One of the Ruby on Rails apps that I work on has a few models that have lots of stuff in them. The Company model in this app is 311 lines long. Now, I know that won't break any records – theUser model in Discourse
Ruby on Rails Rails: Testing for Insecure Admin Routes I have a Ruby on Rails app with an admin section, as is common for a lot of apps. The admin section is namespaced, so all of the controllers are named something like Admin::WidgetsController and the routes all start with /admin. Now, there
Ruby on Rails Rails: Testing for Orphaned Routes Over time, one of my large Ruby on Rails apps has accumulated a lot of cruft in it's routes file. In addition to the normal entropy that accumulates in any large app, I didn't really have a solid grasp of how routes worked when
Ruby on Rails Rails: Is the Attribute Actually Optional? Ruby on Rails model attributes are optional by default. That is, unless you specify otherwise, an attribute is not required for a model instance to be valid. I like to test that this is, in fact, the case. test "weight is not required&
Ruby on Rails Rails: Are the Fixtures Valid? A common pattern in my Ruby on Rails unit tests is to start with a valid instance of a model, make a change to the attribute I'm testing, then assert that the model instance is no longer valid. test "weight is required"