background preloader

Rails

Facebook Twitter

Twitter

Scoping. Caching. Heroku. Sexy Forms in Rails. Rails in a Nutshell. Compiling Ruby, RubyGems, and Rails on Snow Leopard. Monday, 31 August 2009 • Permalink These are instructions for compiling and installing 64-bit Ruby, Rubygems, and Ruby on Rails on Mac OS X 10.6, Snow Leopard. The benefits of manually building a copy of Ruby in /usr/local are detailed here and here. Prerequisites Before following these instructions, you will need: Mac OS X 10.6 Snow Leopard The latest Xcode Tools (from the Snow Leopard DVD or downloaded from Apple — the 10.5 version won’t work) Confidence running UNIX commands using the Terminal If you want to learn more about UNIX and the command line, check out my PeepCode screencast on this topic.

Step 1: Set the PATH Launch Terminal.app from the /Applications/Utilities folder. The first thing we’ll do is set your shell’s PATH variable. If you’re using TextMate like you should be and have installed the UNIX mate command, then you can create and start editing the file like this: mate ~/.profile To the end of this file, add the following line: source ~/.profile echo $PATH Step 2: Download.

Books on Extralogical. A grand piano for your violin. Database indexes What are database indexes? If you're building web apps powered by a relational database, you should know. A database index is a data structure in the database which improves the speed of operations (typically row lookups) on a database table, or across tables. Think of it like the index of a book. If you're reading a book about the Wu Tang Clan and you want to find all the Method Man references, it'd be a lot easier to flip to the index and find "Method Man", then open up directly to all those pages numbers (as opposed to scanning every page of the book for the words "Method Man"), wouldn't it?

Well that's basically how database indexes work. SELECT name FROM users WHERE id = 1 …the database can find that row very quickly, rather than having to scan through every row in the table and check whether it's "id" value is equal to 1. So, in a typical rails application, what things should you index? Primary keys Best practice: index every primary key Foreign keys State columns. Thread safety for your Rails. Rails 2.2 marks the first release of thread safe Rails. But “thread safety” alone, without any context, doesn’t mean shit.

When people say Rails is “thread safe” ( or otherwise ), they usually refer to the dispatching process of Rails. Before 2.2, Rails dispatching looked like : @@guard.synchronize do dispatch_unlocked end And now it looks somewhat like : Long story short, Rails can now serve multiple requests in more than one ruby threads ( or native threads if you’re on JRuby ) parallelly.

You totally should if : You’re using JRuby You’re bold enough to play around with bleeding edge Neverblock stuff Your application has a lot of long running processes, which are not heavy on blocking IO ( this would be rare I imagine ) You totally should NOT if : You’re using Event based mongrel, thin or any of the event based web server in production. You may have heard a bunch of hype about how threads make everything 100x faster, this is far from the truth. Koz’s comments sums it up nicely : In a World of Middleware, Who Needs Monolithic Applications? SmutOnRails. Ruby · diversity tags: A couple of weeks ago there was a Ruby conference in San Francisco called GoGaRuCo (Golden Gate Ruby Conference). This conference has grabbed attention due to a talk at which the presenter illustrated a discussion of CouchDB by using sexually suggestive pictures of women. Unsurprisingly the result has been a fair bit of heated, and occasionally offensive, debate.

The main lines of the debate are familiar. Defenders of the presenter point out that the slides were humorous and no offense was intended. I'll admit to finding much to like in the general edginess of the Rails world. So the view of the rails leadership seems to be this: that the objections to the presentation are yet another attempt to foist empty corporate values on the thriving Rails ecosystem. Except on this occasion I don't see the suits as the people doing the complaining. This incident has now grown beyond a conference presentation and a slide-deck on the web. So where does this go? Further Reading. Customizing Rails Applications on Mac OS X Leopard. Developing Rails Applications on Mac OS X Leopard.

Rolling with Rails 2.0 - The First Full Tutorial - Part 1. Rails 2.0 Step by Step (part 2) This is the second part of my series.Part 1 is here.Thanks for all of the great comments and help.I think one of the most important comments came from enklare who pointed out that with Rails 2.0 you should explicitly set the database when you create a new Rails app by using the -d flag. Instead of using the commandwork$ rails exchange use the commandwork$ rails -d mysql exchange To create the exchange app. ( typing 'rails --help' at the command line will give a short list of available options) This will help Rails configure your application if you have other databases like SQLLite installed.SQLLite is the default database for Rails as of Rails version 2.0. Model View ControllerThe Model View Controller(MVC) design pattern was first described in 1979 by Trygve Reenskaug while working at Xerox on Smalltalk. Following MVC guidelines has been shown to organize applications in a way that makes them easy to manage and maintain.

Model The Model is all about the data. What has been done so far? Rails 2.0 and Scaffolding Step by Step. Rails 2.0 step by step. Part 2 is hereRuby on Rails 2.0 was released by the Rails core team on Friday, December 7th. There were quite a few changes in the 2.0 release, including the way that Rails generates scaffolding code. This change will probably cause trouble for people using tutorials written for previous versions of Rails. I hope this tutorial will help readers get started with Rails 2.0 and keep the community of Rails developers growing. This is the first part of a multi-part tutorial.

This first installment of the tutorial will cover installing Rails and then using Rails to generate a new scaffolded application capable of the four basic database functions of creating, reading, updating, and deleting data. Rails has proven itself to been excellent choice for the needs of most teams and projects. Note:If you are following a detailed tutorial or book based on earlier rails version, it would probably be best to install an earlier version of Rails for use with that book. Extending Your Models Using Custom Plugins, Or, A Brief Introduc. The Present and Future of Ruby and Rails. Chad Fowler and Rich Kilmer are well-known Ruby programmers, authors, and leaders. Along with David A.

Black , they were co-chairs of the recently concluded RailsConf Europe 2008 . In this interview with O'Reilly, Chad and Rich discuss where Ruby and Rails have gone in the past year, whether RESTful composition obviates the need for ORM, what's interesting in the upcoming world of Ruby and Rails, and how Maglev, Rubinius, and other new Ruby implementations contribute to the world of dynamic languages. : Okay; I guess I'll take that initially. New in the world of Rails--I think the big thing is that there's not a lot new which sounds kind of boring but it kind of means that we're reaching a point that things have matured and stabilized. It used to be kind of a joke that Rails releases would keep coming out and keep breaking things and you kept having to upgrade your apps.

I've worked with a lot of XML interfaces to services that wing it. . : No; you can actually do both with them. REST With Rails Part 1. We Recommend These Resources In this first part I will show you how to build RESTful services using Rails. REST is an architectural style modeled after the Web. Basically, it codifies the principles and methods behind Web servers that lead to the creation of the largest distributed system ever built. For some people "distributed" is about the plumbing – sending messages to remote servers – we're also thinking of the way large scale systems emerge from smaller services, built independently by different groups of people—distributed in design and in implementation. When we think of REST, we think of following those very same principles. Modeling our services in terms of resources, making sure they are addressable as URLs, connecting them by linking from one resource to another, handling representations based on content type, performing stateless operations, and so forth.

This article is based on chapter 5 from Ruby in Practice by Jeremy McAnally and Assaf Arkin. 3.map.resources :tasks 4.end. Fear And Loathing At RailsConf. Chad Fowler wrote a great book. And then said some strange things: Photo by James Duncan Davidson They're both reasonable things to say, it was just really weird to hear them combined like that. Chad also did a little video interview with Gregg Pollack from Rails Envy. Take a second and check it out: In it Chad says that the Ruby community has a good tradition of weird because for years this wasn't something you could get a day job doing.

He also says "a lot of people" have complained about RubyConf being on a weekend. Problem is, to my knowledge only one person has complained about that. This subtle falseness in Chad's reasoning led me to see another subtle falseness as well. It makes a difference. Let's make another subtle change. What if the Ruby community has a tradition of weirdness, and it used to be that this wasn't something many people could get a day job doing? This would be the historically accurate version. How can we achieve it? Or let's make yet another subtle change.

Update: Move Over, AJAX, ARAX Is Here. Move over, AJAX; Microsoft is pushing a different scenario, known as Asynchronous Ruby and XML, or ARAX. At the RailsConf conference for Ruby on Rails developers in Portland, Ore., on May 30, John Lam, creator of the IronRuby project at Microsoft, told eWEEK that as Microsoft's Silverlight rich Internet application environment takes off it will provide Ruby developers with a way to deliver AJAX (Asynchronous JavaScript and XML)-style applications without having to use JavaScript.

"If you're a Ruby programmer and you like Ruby as a language, context-switching into JavaScript is just something you have to do," Lam said. "It's a tax. You're trading productivity away arbitrarily because that's just what runs in the browser. And it's much more interesting when you can run the same language on both sides [the client and the server] so you don't have to do that context switch. " The creator of Ruby on Rails argues for broad development experience at RailConf. Click here to read more. Darryl K. Rolling with Rails 2.1 - The First Full Tutorial - Part 1. Unpacked gem: ‘/Users/akitaonrails/rails/sandbox/screencasts/blog/vendor/gems/haml-1.8.0’ Unpacked gem: ‘/Users/akitaonrails/rails/sandbox/screencasts/blog/vendor/gems/launchy-0.3.2’ Unpacked gem: ‘/Users/akitaonrails/rails/sandbox/screencasts/blog/vendor/gems/defunkt-github-0.1.3’ Unpacked gem: ‘/Users/akitaonrails/rails/sandbox/screencasts/blog/vendor/gems/launchy-0.3.2’ Notice that most of the gems changed from the [I]nstalled status to [F]rozen.

But, the HAML gems was copied but for some reason it still shows up as [I] instead of [F], probably a small bug in the Edge version. I would expect all gems to show as [F]. Anyway. Let’s say we required another gem that by itself requires native compilation, for instance, RMagick, so let’s add another line in the environment.rb file: Particularly, we have to ‘know’ that the gem is named ‘rmagick’ but it is required as ‘RMagick2’. Now, we unpack them to our vendor folder using the same “gems:unpack:dependencies” command. Stone: Dead-Simple Data Persistence. Sections What Installing Getting Up and Running Rails Merb Everywhere Else Usage Models Get, Post, Put, and Delete A Word About Finding Stuff License Contributing Contact For small applications, a database can be overkill for storing your data in a consistent and organized manner.

You can check out an application that uses Merb+Stone here. The source for that blog is here. sudo gem install stone Up and Running Create a new file in config/initializers called stone.rb Add the following code to your new file: require ' stone ' Stone . start ( Dir . pwd , Dir . glob ( File . join ( Dir . pwd ," app/models/* ")), :rails ) Open your environment.rb file and look for the following lines: Uncomment the last of those lines, and leave only active_record, so that it looks like this: config . frameworks -= [ :active_record ] Create some models!

Stone-gen model Author name:string Add the following code to your init.rb file: Stone was designed to provide easy data storage management for app, not just web ones. That’s it!