Showing posts with label rails. Show all posts
Showing posts with label rails. Show all posts

Sunday, August 8, 2010

Stupid Rails Gothcha 01

Ok, here's one of those "I just wasted X hours, damn it!" moments. I installed Cucumber into a Rails App that uses the shopify_app plugin. And it keept giving me strange errors when running
rake cucumber
Turns out I should have installed Cucumber first then when I generated the shopify stuff it would have setup a correct `shopify.yml` and in the end all I needed to do was duplicate a few lines in `shopify.yml`. Remember all your environments need to know about your api key.

I hope this helps someone.

Saturday, April 3, 2010

Stupid Rails Gothcha 00

Ok so, its another of those situations, where I spent way too long trying to track down strange behavior in my code, and I don't want to repeat the process. So I'm writing it down to help myself remember. And maybe just maybe someone else will find this post and save themselves a couple of hours.

So here's the situation I have two very similar views for different models. On one the footer mysteriously shows up in the middle of the page and the other works fine with the footer showing up at the bottom like it should.

It turns out that rails views, at least ".html.erb" ones, cannot handle comments in
<% %>
blocks. I had code like:

<% for @collection.each do |thing| %>
    display thing ...
<% end #each %>

Which caused the footer in the middle issue. When I changed it to:

<% for @collection.each do |thing| %>
    display thing ...
<% end %>

The view was fixed and the day was saved! What the fuck rails, comments should never ever break things! Grrr, anyway live an learn and remember no comments in your views, lest the rails daemons become angry.

Tuesday, May 19, 2009

Custom Titles in Rails

One thing I've learned while building rails sites is that changing things in the header on a view-by-view basis can be tricky. This starts becoming important when you start optimizing your page for Google. One thing Google likes is descriptive and non-repetitive title tags. To get view by view customized title tags try this.
  1. Add `<%= yield(:title) || "Default Title" %>` to your layout inside your title tag.
  2. Add `<% content_for(:title, "Custom Title") %> to your view file.
You can replace "Custom Title" with code such as `@object.name` or anything else that returns a string for even more dynamic titles. I've had to look this technique up more than once now so I'm blogging it in an effort to better remember it. I hope it is useful to you as well. You can use this technique to put other things in the header as well just use `yield` and `content_for` judiciously.