#222
Jul 12, 2010

Rack in Rails 3

The router in Rails 3 is fully compatible with Rack. Learn how to embed Sinatra into an app, handle redirects, and improve on Rails Metal.
Download (12.1 MB, 8:48)
alternative download for iPod & Apple TV (12 MB, 8:48)

Resources

# routes.rb
root :to => "home#index"
root :to => HomeController.action(:index)
root :to => HomeApp

match "/about" => redirect("/aboutus")
match "/aboutus" => "info#about"

resources :products
match "/p/:id" => redirect("/products/%{id}")

match "/processes" => ProcessesApp.action(:index)

# Gemfile
gem "sinatra"

# lib/home_app.rb
class HomeApp < Sinatra::Base
  get "/" do
    "Hello from Sinatra!"
  end
end

# lib/processes_app.rb
class ProcessesApp < ActionController::Metal
  include ActionController::Rendering
  
  append_view_path "#{Rails.root}/app/views"
  
  def index
    @processes = `ps -axcr -o "pid,pcpu,pmem,time,comm"`
    render
  end
end
<!-- app/views/processes_app/index.html.erb -->
<h1>Processes</h1>
<pre><%= @processes %></pre>

RSS Feed for Episode Comments 26 comments

1. Inuki Jul 12, 2010 at 01:53

Thx Ryan for this screencast


2. Paul Koch Jul 12, 2010 at 02:19

Excellent screencast!
Thank you, Ryan!


3. Hussein Morsy Jul 12, 2010 at 02:42

Thanks Ryan for the advanced topics about rails 3


4. Tex Jul 12, 2010 at 03:21

Many thanks Ryan !!!


5. nunu Jul 12, 2010 at 05:35

Aren't there any sponsors for now?


6. Dinooz Jul 12, 2010 at 06:31

As always awesome screencasts Ryan, thank you, let me ask you something, what would be the approach for caching tecniques in Rails 3?

Keep doing the great job.


7. James Jul 12, 2010 at 06:51

I started learning Rails about 2 months ago and I would just like to say thanks, your screen casts have been a great help during this time and I look forward to more excellent learning experiences from your site! Thanks!


8. Andy Jul 12, 2010 at 09:01

How would you do authentication / authorization for embedded apps??


9. Jim Jul 15, 2010 at 02:21

I haven't tested Rails Metal yet but I know that this would be a good resource when the time comes.

Thanks!


10. Futbolka Jul 16, 2010 at 04:21

What is this?


11. elvankent halı yıkama Jul 22, 2010 at 00:12

Thank you for your share!


12. Dmitry A. Ustalov Jul 26, 2010 at 02:34

Please note that Metal is deprecated and removed since Rails 3.0.0.beta4.

https://rails.lighthouseapp.com/projects/8994/tickets/4889-rails-300beta4-metal-absent


13. Konstantin Jul 26, 2010 at 16:59

Here is a blog post on how to get Metal-like application enabled in a new Rails3 app:

http://tektastic.com/2010/07/rails3-rack-and-where-did-my-metal-go.html


14. fivefingers kso Jul 26, 2010 at 23:34

fivefingers kso


15. oakley sunglasses Jul 30, 2010 at 22:10

Here is a blog post on how to get Metal-like application enabled in a new Rails3


16. APPLE IBOOK 2000 MODEL battery Jul 30, 2010 at 23:13

Thank you for your share!


17. Asus Eee Pc Laptop Battery Jul 30, 2010 at 23:14

Excellent screencast!
Thank you, Ryan!


18. boots Aug 01, 2010 at 19:28

urces :products
match "/p/:id" => redirect("/products/%{id}")

match "/processes" => ProcessesApp.action(:index)


20. canli mac izle Aug 05, 2010 at 11:27

thanks..good sharing


21. UGG Boots on sale Aug 10, 2010 at 18:38

Gooooooooooooooooooood luck ~~!!


22. Jordan sale Aug 11, 2010 at 19:20

wonderful screencast
nice article
thanks for sharing


23. Makc Aug 12, 2010 at 03:02

Thank you, just come in handy


24. fake Bally handbags Aug 13, 2010 at 03:17

 I learned how to embed Sinatra into an app, handle redirects, and improve on Rails Metal.thank you.


25. Fake wallets Aug 13, 2010 at 03:22

it is ver useful ,thank you.


26. Replica Wallets Aug 13, 2010 at 03:23

that's what i am looking for ,thanks.


27. oppo Aug 15, 2010 at 08:37

This was really useful. Thanks Ryan!


28. Rip Blu-ray for Mac Aug 18, 2010 at 01:25

Thanks,it's so good.
suport!


29. wholesale new era caps Aug 20, 2010 at 19:57

Generally I do not post on blogs, but I would like to say that this post really forced me to do so, Excellent post!


30. converse all star Aug 20, 2010 at 20:36

love converse all star,love yourself.Warm welcome.


31. converse all star Aug 20, 2010 at 20:54

love converse all star,love yourself.High quality low price.It's fit for you.


32. tile floor vacuum Aug 24, 2010 at 10:24

The blog article very surprised to me! Your writing is good. In this I learned a lot! Thank you!


33. cheap clothing Aug 24, 2010 at 19:06

David Heinemeier Hansson..thanks


34. PDF to Images Converter Aug 24, 2010 at 22:51

Some times, to a certain need, we have to convert PDF to image for enjoyment.


35. pc games Aug 25, 2010 at 18:42

Thanks for such a great post and the review, I am totally impressed! Keep stuff like this coming.


36. louis vuitton shoes Aug 26, 2010 at 21:13

Thanks for sharing your article. I really enjoyed it. I put a link to my site to here so other people can read it. My readers have about the same interets


37. Antique Website Designs Aug 27, 2010 at 12:11

The Sinatra example no longer works in the Rails 3 rc2 release. Any ideas on how to get this operational? I suspect that either the lib directory is not being loaded or support for Metal has been removed as Konstantin's article.
~statique


38. Antique Website Design Aug 27, 2010 at 12:28

As it turns out, the Sinatra example is not operational because Rails 3.0.0.rc2 does not load the lib directory. Austen Conrad posted an article with a fix to this problem by adding His full article is here: http://blog.arconrad.com/?p=1282

An alternative to wildcard loading the lib, one could create an initializer to load the app specifically.
~statique


39. mbt shoes sale Aug 28, 2010 at 10:01

nice article
thanks for sharing


40. cheap mbt shoes Aug 28, 2010 at 10:11

Thanks,it's so good.
suport!


41. cheap ugg boots sale Aug 28, 2010 at 10:19

Please note that Metal is deprecated and removed since Rails 3.0.0.beta4.


42. rap Aug 29, 2010 at 08:46

Thanks,it's so good.
suport!


43. replicahandbags Aug 30, 2010 at 19:16

I have always liked Outdoor movies, a child standing at the window, looked out from home

to the following. Will be able to see the staff busy figure, a huge white cloth has a

child hang up and soon will be able to see the movie.


44. snow boots Aug 30, 2010 at 20:08

Generally I do not post on blogs, but I would like to say that this post really forced me to do so, Excellent post!


45. herve leger dress Aug 30, 2010 at 20:11

Thanks for sharing your article. I really enjoyed it. I put a link to my site to here so other people can read it.


46. louis vuitton sunglasses Sep 01, 2010 at 22:38

Extremely great post, really beneficial stuff. Never thought I’d find the facts I would like in this article. I’ve been looking all over the net for some time now and was starting to get irritated.

Add your comment:

(SKIP THIS ONE)

(required)

(not shown)


(use pastie or gist for code)

sponsored by:
if you want to help:
required:
Get Quicktime Player
Give Back to Open Source