Have you ever wished you could mix Rack or Sinatra into your Ruby on Rails application just to get its raw throughput on certain parts of your application?
Let’s face it, sometimes, the Rails framework is overkill when we’re returning a simple string or an object in JSON as our response. Your answer for these instances is here. Rails Metal.
Performance
Some people have reported huge speed increases in Rails Metal over the Rails MVC framework. This article claimed a 25x increase over Rails. Pratik Naik from the Rails Core team benchmarked a more believable increase of 4x. Whatever the case, the performance advantage is worth noting.
Read More
activerecord, controllers, erb, HTML, http, middleware, rack, Rails, Rails Metal, response, Ruby, views
Have you ever wished you could call yield multiple times in the same layout in order to get extra stylesheets, javascript, or a dynamic sidebar? Having worked on several projects that needed this soft of functionality, I’ve probably built this in three or four times. Then I started watching railscasts.
There’s a method called content_for that provides this functionality. All you have to do is call content for in your view. Here’s the erb markup:
<% content_for :head do %>
<%= stylesheet_link_tag :my_style %>
<% end %>
Then, in your layout all you have to do is call yield like you normally would in your layout with on small difference. Here’s the erb markup.
I picked up this tip from Ryan Bates Railscast Episode #8
content_for, erb, layout, Ruby on Rails, views, yield
When I started writing part II, I started writing about models. As I got a little further along, I realized that it would be more helpful to provide an overview of the controller, which provides the data that goes into your web page, before I showed you how to get the data out of the database. My hope is that you’ll read this thinking of how you want the data provided, which adds context to part III on models.
Controllers are Where the Work Gets Done
Have you ever worked with one of those people who knows exactly where to go to get everything he needs. Can delegate his tasks effortlessly, and then pull it all together in the end. That guy would be our controller. When your website’s user browses to the page, the Rails engine picks up the request and decides which controller to send it to. More specifically, it decides which method in the controller to send it to. The methods on the controller are referred to as actions.
Read More
controllers, Database, erb, HTML, Rails, Ruby, Ruby on Rails, tutorial, views