Posted by ryan
at 5:32 PM
on Sunday, September 07, 2008
With the upcoming thread-safety of Rails comes the necessity of database connection pools. While less a feature and more a hidden implementation detail, you do have the ability to adjust the max size of these new pools (default is 5). In your database.yml configuration file just set the pool key:
1
2
3
4
5
|
development:
adapter: mysql
username: root
database: myapp_dev
pool: 10 |
So there ya go – connection pools. That was easy…
tags: ruby,
rubyonrails
Posted by ryan
at 5:10 PM
on Sunday, September 07, 2008
Rails mailer templates now have the ability to utilize layouts just like their view-template siblings. The only caveat is that for a mailer layout to be automatically recognized it must end with _mailer. So this mailer:
1
2
3
4
5
6
|
class UserMailer < ActionMailer::Base
def registration(user)
subject "You've registered"
from "system@example.com"
end
end |
would need a layout at layouts/user_mailer.html.erb. If you explicitly specify the layout it doesn’t need the _mailer suffix. So, in this example, a layout at layouts/email.html.erb would suffice:
1
2
3
4
|
class UserMailer < ActionMailer::Base
layout 'email'
...
end |
Go forth and make your emails pretty. You’ve got all the tools now…
tags: ruby,
rubyonrails
Posted by ryan
at 4:32 PM
on Sunday, September 07, 2008
Rails’ routing mechanism is pretty slick. In a very intuitive way you’re able to describe the resources you want exposed at the URL level with this routing-DSL:
1
2
3
4
5
|
map.resources :users do |user|
user.resources :articles do |article|
article.resources :comments
end
end |
However, while this configuration makes an article available at /users/1/articles/1 and comments at /users/1/articles/1/comments/1 there are often times when you want to bypass the full nested hierarchy and directly access the resource in question. Now, with the shallow route option, you can.
1
2
3
4
5
|
map.resources :users, :shallow => true do |user|
user.resources :articles do |article|
article.resources :comments
end
end |
This configuration removes all nested member paths (like /articles/1/comments/1) and makes them directly accessible (as /comments/1). Basically, routes are built only with the minimal amount of information that’s needed to uniquely identify the resource.
1
2
3
4
|
user_articles_path(1) #=> '/users/1/articles'
article_path(2) #=> '/articles/2'
article_comments_path(3) #=> '/articles/3/comments'
comment_path(4) #=> '/comments/4' |
No longer do you need to wrestle with infinitely nested routes, the :shallow option automatically makes all routes as concise as possible.
tags: ruby,
rubyonrails