Showing posts with label rails. Show all posts
Showing posts with label rails. Show all posts
Wednesday, August 8, 2012
Make it easier to use partials with blocks in rails
The shorter version of render :partial is widely known and used. These are equivalent, but the second version is so much more succinct and readable.
To use a partial with a yield in it, (what I call a "block partial"), you can use render :layout which a. doesn't read very well, (it's a partial, not a layout clearly), and b. can't be shortened nicely the way that render :partial can.
So here is block_render:
It lets you have nice neat render calls like this:
This is a real-life example of a block partial I like to use. Those classes are bootstrap classes for making a nice drop down menu.
Wednesday, February 8, 2012
Make ActiveRecord::Base#create respect the :type attribute
I think I've needed and implemented this twice now, so let's make a post about it.
The problem occurs when you are using f.fields_for and nested forms, as per these railscasts, and the nested objects are using STI.
(Will leave a more detailed explanation for future posts).
Update 1: Even though this works as described, I don't think it solves my problem. Will post again if I figure it out...
Update 2: Found this which is I think what I was using last time I had this problem... :S
Monday, October 3, 2011
Tuesday, September 20, 2011
A Rails 3 gotcha with html_safe
This was causing me to scratch my head a bit today. I'm glad I know what's going on now and why you need to use safe_concat. It still seems a little unintuitive though.
For more into see the explanation here (under the "the tricky part") and the api docs on ActiveSupport::SafeBuffer
My (first) contribution to Rails
I fixed a little mysql configuration bug in Rails. It counted as three commits (even though they are the same thing, just in different branches), which puts me unfairly into the top 500 all time committers. ;) See here.
You'd think DHH would be number one, but actually he's not. Take a look at the list.
Here is my original pull request if you'd like to read more about it.
Ps, I also reported a capybara bug (along with a failing test) that got fixed pretty quickly. But my fork didn't get merged so none of my commits are recorded. :P
You'd think DHH would be number one, but actually he's not. Take a look at the list.
Here is my original pull request if you'd like to read more about it.
Ps, I also reported a capybara bug (along with a failing test) that got fixed pretty quickly. But my fork didn't get merged so none of my commits are recorded. :P
Subscribe to:
Posts (Atom)