With changeset 6951, every employee of Elevated Rails is now a core contributor. I’ll talk a little about what that change means and how the integration of simply helpful into rails core makes life a little easier.
The new restful/CRUD conventions have made rails significantly easier to develop for. I love being able to say
<%=link_to "Show Group", group_path(@group)%>
and not have to worry about specifying the controller, action and id.
The simply_helpful plugin can make things even easier. You can simply say
<%= link_to "Show Group",@group%> and it will do the right thing.
That’s nice, but not earth shattering. The real beauty comes in form handling. With form for, you can say things like:
<% form_for @group, :builder=>MyFormBuilder do |f| %> <%= f.text_field :name%> <% end %>
It may not look like much, but look at what is missing. We don’t have to specify the :url parameter, it is inferred from the object. We also don’t have to specify the :method parameter as either put or post. Form_for is smart enough to see if the record has an id, and will do the right thing. That means you can use exactly the same form_for statement for create and update.
But wait, There’s more! Redirect_to got the same goodness. You can say
redirect_to @tag.taggable and not have to know what type of object the polymorphic association points to.
Unfortunately, there was some ugliness. If you used nested resources, this love was off limits to you. Up until today, you could only use these methods on a single object. simply_helpful was moved into the core a while back, but still had these issues. Jonathan’s patch builds off of a patch for simply_helpful and fixes this. As of today, you can say:
<% form_for [@group,@tag], :builder=>MyFormBuilder do |f| %> <%= f.text_field :name%> <% end %>
and it will go to the Tag resource nested under groups. Because it is polymorphic, you don’t even need to know what the first object is. For instance, we have a system with comments on many types of objects. To edit a comment, we can now say
<%= link_to @comment.title,edit_polymorphic_path([@comment.commentable,@comment])%> to edit the comment, or just
<%= link_to @comment.title,[@comment.commentable,@comment]%> to show it!
It’s amazing how much easier it is to build rails applications today than it was a year ago!