background preloader

Rails

Facebook Twitter

The Ruby on Rails World. Objects on Rails. Now that we've got persistence working, let's add a rudimentary RESTful API to our blog.

Objects on Rails

Really RESTful APIs make heavy use of hyperlinking in the resource representations they serve. For instance, a JSON representation of a blog post might look something like this: Example JSON representation of a blog post Constructing hyperlinked responses like this one presents us with a problem. Normally, when rendering HTML representations, we render links to other resources using the various routing helpers (such as url_for or #post_url) that Rails provides for us inside of view templates. For instance, here's an implementation of Post#show that uses Rails' #respond_with method: def show @post = Post.find(params[:id]) respond_with(@post) end Using respond_with to render a post (If you're looking at Post.find and calling out "Lone Wolf object!

" In the absence of a template at [posts/show.json], a request for a post in JSON format will result in call to Post#to_json. prev next up LinkExhibit Well, almost. The Joke Is On Us: How Ruby 1.9 Supports the Goto Statement. The goto statement is one of the most infamous and troublesome features of old, archaic languages like Fortran.

The Joke Is On Us: How Ruby 1.9 Supports the Goto Statement

It allowed programmers to quickly create spaghetti code that was confusing and impossible to understand. Thankfully when structured programming came into use in the late 1960s and 1970s with Algol, Pascal and later C, goto was no longer necessary. This is all ancient history: why am I bringing it up? Well, I just discovered this week that Ruby, one of the most beautiful and expressive languages in use today, includes support for the goto statement! Here’s how it works: Exploring the Elegance of Sinatra: A Lightweight Alternative to Rails.

We all know Sinatra as a lightweight alternative to Rails.

Exploring the Elegance of Sinatra: A Lightweight Alternative to Rails

I find using it is a real pleasure. Sinatra’s helper methods, template support and routing provide just enough to get a simple web site running quickly, but then immediately get out of your way. Years after it was introduced Sinatra remains one of the most popular Ruby web frameworks out there. The Pragmatic Bookshelf. March 28, 2012 Modern web development involves a lot of moving parts and a lot of different technologies, and it can be hard to get them all just right.

The Pragmatic Bookshelf

In the heat of development, it’s particularly easy to neglect the presentation layer until it grows to become an unmanageable mess. But you can fix that Broken Window with The Rails View, now in print and shipping from pragprog.com/book/warv. Ruby on Rails Tutorial: Learn Rails by Example book and screencasts by Michael Hartl. Michael Hartl Contents Foreword My former company (CD Baby) was one of the first to loudly switch to Ruby on Rails, and then even more loudly switch back to PHP (Google me to read about the drama).

Ruby on Rails Tutorial: Learn Rails by Example book and screencasts by Michael Hartl

This book by Michael Hartl came so highly recommended that I had to try it, and the Ruby on Rails Tutorial is what I used to switch back to Rails again. Though I’ve worked my way through many Rails books, this is the one that finally made me “get” it. The linear narrative is such a great format. Enjoy! Derek Sivers (sivers.org) Founder, CD Baby Acknowledgments. Rails Routing from the Outside In. 1 The Purpose of the Rails Router The Rails router recognizes URLs and dispatches them to a controller's action.

Rails Routing from the Outside In

It can also generate paths and URLs, avoiding the need to hardcode strings in your views. Best way to learn Ruby & Rails - @AstonJ's Blog. Ruby on Rails 3 Testing with RSpec 2. The Best Way to Learn Rails. I come from a PHP background, but these days, I'm a full-time Rails developer.

The Best Way to Learn Rails

The difficulty for most people who make the switch lies in the learning curve that’s involved. Once you've become proficient in a language or framework, switching to a new one feels like an unnecessary (and time-consuming) challenge. However, learning Ruby and Rails is actually pretty easy! It's an incredibly powerful framework, and has a huge community pushing it along. Ruby on Rails Guides. RubySource » Everything About Ruby On Rails Development and Database Programming. Ruby on Rails Tutorial: Learn Rails by Example book and screencasts by Michael Hartl.

Michael Hartl Contents Foreword My former company (CD Baby) was one of the first to loudly switch to Ruby on Rails, and then even more loudly switch back to PHP (Google me to read about the drama).

Ruby on Rails Tutorial: Learn Rails by Example book and screencasts by Michael Hartl

This book by Michael Hartl came so highly recommended that I had to try it, and the Ruby on Rails Tutorial is what I used to switch back to Rails again. Though I’ve worked my way through many Rails books, this is the one that finally made me “get” it. The linear narrative is such a great format. Enjoy! Derek Sivers (sivers.org) Founder, CD Baby Acknowledgments The Ruby on Rails Tutorial owes a lot to my previous Rails book, RailsSpace, and hence to my coauthor Aurelius Prochazka. I’d like to acknowledge a long list of Rubyists who have taught and inspired me over the years: David Heinemeier Hansson, Yehuda Katz, Carl Lerche, Jeremy Kemper, Xavier Noria, Ryan Bates, Geoffrey Grosenbach, Peter Cooper, Matt Aimonetti, Gregg Pollack, Wayne E.

About the author Copyright and license 3.1 Static pages. (class 1 of 6) Efficient Rails Test-Driven Development - by Wolfram Arnold. Coding in the rain · Modern Ruby Development. Ruby on Rails Tutorials for Web Development Beginners.