How to Check If Someone is Invisible, Offline Or Blocked You On GTalk

November 12, 2010

GTalk is one of the most used messaging services on internet.

Initially Gtalk was not having any invisible option in it. Which means you will get noticed by all your friends once you log in. But later, after a lots of requests from it’s users, GTalk decided to start this invisible feature. But, they started this invisible feature for those who uses GTalk from GMail or Orkut. If you are using GTalk from your desktop, you may not get this facility.

In this post I will guide you with three things that you might find interesting. You can consider these as GTalk tricks. And the three things are:

  1. How to know if someone is invisible on GTalk.
  2. How to know if someone is offline or not.
  3. How to know if someone has blocked you on Gtalk or not.

Lets get started step by step. I am sure, you will have fun reading these Gtalk tricks.

How To Know if Someone is Invisible or Offline on GTalk :

People activate this invisible feature for many reasons. They might be busy or do not want anyone to disturb them. They want to chat with few people they want or they want to stay hidden and contact the persons they wish. I always stay invisible on Gtalk, so that I can talk with the persons I want

Now if you want to fool the people and know about their online status even when they have logged in with invisible feature activated, then this is possible. Poor Gtalk! There are two ways to do this.

  • After  the Gtalk  installation, log on to your GTalk account with your login details.
  • Now, this will show you the entire online friends list. It does not matter if they are online or invisible.
  • In this way you can catch your offline friends as well. The persons who are being shown as offline, are not present on GTalk.
  • And you are done above. You will notice those online (visible + invisible) as well as the offline friends.

And the second method  is :

  • Set the chat as off the record with target user. This can be done only when the other user is online.
  • Now try sending chat to that user when he is invisible or offline.
  • If he is invisible, then he will receive chat.
  • But if he Is offline, then you will receive error “<username> did not receive your chat”.

How to Know if Someone Has Blocked You on Gtalk :

Now this is worth exciting. Few times we notice friends not contacting us for a long time. Even though we send them messages, they never reply us back. It can happen because of three reasons.

He/She is avoiding  or offline blocked you on Gtalk.

Whatever the reson may be, it’s nice to find the reason yourself. Let’s find out the exact reason of not getting a reply back. But for this you need to have PIDGIN and configure it properly. Pidgin is a third party tool, available for free. You can use all your messenger accounts at once using this software. You can talk to your friends using AIM, ICQ, Jabber/XMPP, MSN Messenger, Yahoo!, Google Talk, Bonjour, Gadu-Gadu, IRC, Novell GroupWise Messenger, QQ, Lotus Sametime, SILC, SIMPLE, MySpaceIM, Zephyr etc. Read the below steps properly.

How to configure PIDGIN for GTalk :

  • Download Pidgin.
  • Go To Accounts –> Manage –> Add.
  • It will open a new window Add Accounts.
  • From the drop down box choose XMPP as the Protocol.
  • In case of Screen name enter your Gmail Id (e.g. – solid.blogger).
  • Type gmail.com as the Domain/Server.
  • In Resource Field enter Home.
  • Type your Gmail Password in the Password Field.
  • Choose any Nickname (e.g. – Bapun) as Local alias.

And you are done with Pidgin settings. Now lets play with Pidgin to find those GTalk contacts who has blocked you. For this follow the below mentioned steps.

1. sign in to GTalk on PIDGIN with your details

2. Go to Buddies –> Show Offline Buddies (The person who has blocked you is being shown as offline to you. So, in this way you can catch him.)

3. Now all available contacts will be visible to you. Select any one contact from that list.

4. Right click on that selected contact, and click on Get Info.

5. Now here is the twist. Clicking on Get Info will show the brief profile of the person. But now if the person has blocked you on Google Talk, you won’t be able to see his/her full profile. You can’t even see his/her profile name.

This is the best way to know if someone has blocked you on google talk or not. If he has blocked you, then he will appear to you forever.


Silverlight with Ruby on Rails

April 17, 2008

Using Silverlight with Ruby on Rails

In this post I will be showing a really simple example of creating a Silverlight frontend for a Rails backend. This is what I think will be a three part series comparing Silverlight with Flex.

The steps will be:

  1. Creating a Rails application.
  2. Creating a frontend for it in silverlight.
  3. Creating a frontend for it in Flex.
  4. Comparing the approaches taken in both the frontends.

I will try to keep changes in the backend Rails application to a minimum.

Creating a Rails Application
F:\>rails test
F:\>cd test
F:\test>ruby script\generate scaffold user name:string address:text
F:\test>rake db:create
F:\test>rake db:migrate
F:\test>ruby script\server

Before running the migrations add the following code in the first migration file (./db/migrate/001_create_users.rb) to create some initial data. So it should look like:

class CreateUsers < ActiveRecord::Migration
def self.up
create_table :users do |t|
t.string :name
t.text :address
t.timestamps
end

User.create(:name=> “Gaurav”, :address=> “Gaurav’s address”)
User.create(:name=> “Rishav”, :address=> “Rishav’s address”)
User.create(:name=> “Bhavesh”, :address=> “Bhavesh’s address”)
end

def self.down
drop_table :users
end
end
Creating a new C# based Silverlight project

Open up Visual Studio 2008 (with Silverlight tools installed. You can also download a trial version of Visual Studio 2008 from here). And create a new project:

vs_step1

vs_step2

Open the page.xaml file and add a ListBox to it. It should look like:

<UserControl x:Class=”TestFrontEnd.Page”
xmlns=”http://schemas.microsoft.com/client/2007″
xmlns x =”http://schemas.microsoft.com/winfx/2006/xaml”
Width=”400″ Height=”300″>
<Grid x:Name=”LayoutRoot” Background=”White”>
<ListBox x:Name=”userList” Height=”200″/>
</Grid>
</UserControl>

Now when the server responds with xml, we will parse that using Linq. For that we need a User class that is like the user model on the Rails side. So it should have 3 fields:

  1. id
  2. name
  3. address

It should look like:

namespace TestFrontEnd {
public class User {
public int id { get; set; }
public string name { get; set; }
public string address { get; set; }
}
}

To make things simpler I have created a HTTPService class that behaves something like the Flex based HTTPService class. Here is the source (too big to paste inline). Add it to your project. You will need to include System.Net assembly your project to to make it work. Its usage is quite simple.

HTTPService userIndexService = new HTTPService();
userIndexService.Url = “http://localhost:3000/users.xml”;
userIndexService.ServiceComplete += new HttpServiceCompleteEventHandler(userIndexService_ServiceComplete);
userIndexService.send();

You can also give the request method like:

userIndexService.Method = “POST”;

Now add an ObservableCollection to the Page class:

private ObservableCollection<User> userListItems = new ObservableCollection<User>();

We will be using this for databinding with the ListBox to display all the users.

Add the System.Xml.Linq to your project. In the userIndexService_ServiceComplete event handler write:

void userIndexService_ServiceComplete(HttpServiceCompleteEventArgs e) {
XDocument users = XDocument.Parse(e.Response);
User[] usersList = (from x in users.Descendants(“user”)
select new User
{
id = int.Parse(x.Descendants(“id”).First().Value),
name = x.Descendants(“name”).First().Value,
address = x.Descendants(“address”).First().Value,
}).ToArray();
foreach (User user in usersList)
userListItems.Add(user);
}

So when the service completes all the users will be filled in the ObserveableCollection. Now to bind it to the userList ListBox. In the constructor of the Page class write:

userList.DataContext = userListItems;

And modify the code for the userList ListBox to look like:

<ListBox x:Name=”userList” Height=”200″ ItemsSource=”{Binding}” DisplayMemberPath=”name” />

Add a crossdomain.xml file to the rails project’s public folder:

<?xml version=”1.0″?>
<!DOCTYPE cross-domain-policy SYSTEM “http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd”>
<cross-domain-policy>
<allow-access-from domain=”*” />
</cross-domain-policy>

We are basically allowing our Silverlight app to access the rails server. You won’t be requiring this file if the Rails server is serving the Silverlight application, but currently it is not the case.

Now when you run the code you should see:

vs_step3

Now I will add a few more lines of code to show the selected item in TextBox. Add/Update the following to page.xaml:

<ListBox x:Name=”userList” Height=”200″ ItemsSource=”{Binding}” DisplayMemberPath=”name” SelectionChanged=”userList_SelectionChanged”/>
<StackPanel x:Name=”controls”>
<TextBox Text=”{Binding name, Mode=Twoway}” x:Name=”userName”/>
<TextBox Text=”{Binding address, Mode=Twoway}” x:Name=”userAddress”/>
</StackPanel>

The first TextBox is showing name and second is showing the password. The binding mode is set to TwoWay so that the changes in TextBox are automatically to the userListItems.

Add the corresponding event handler to Page class:

private void userList_SelectionChanged(object sender, SelectionChangedEventArgs e) {
controls.DataContext = userList.SelectedItem as User;
}

Now when you run the code you should see:

image

Download the code upto this point:

Implementing the full CRUD :

Firstly I willl be doing a bit of refactoring. Move the xml parsing code using Linq to the User class. So it should now look like:

public class User {
public int id { get; set; }
public string name { get; set; }
public string address { get; set; }

public static User[] users_from_xml(String xml_string){
XDocument users = XDocument.Parse(xml_string);
return (from x in users.Descendants(“user”)
select new User
{
id = int.Parse(x.Descendants(“id”).First().Value),
name = x.Descendants(“name”).First().Value,
address = x.Descendants(“address”).First().Value,
}).ToArray();
}

public static User user_from_xml(String xml_string) {
return users_from_xml(xml_string).First();
}
}

Change the Page class to:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.ObjectModel;
using System.Xml.Linq;

namespace TestFrontEnd {
public partial class Page : UserControl {
private ObservableCollection<User> userListItems = new ObservableCollection<User>();

private HTTPService userIndexService;
private HTTPService userCreateService;
private HTTPService userUpdateService;
private HTTPService userDeleteService;

public Page() {
InitializeComponent();
// setting the databinding
userList.DataContext = userListItems;
controls.DataContext = new User();

// service to get all te users form the server
userIndexService = new HTTPService();
userIndexService.Url = “http://localhost:3000/users.xml”;
userIndexService.ServiceComplete += new HttpServiceCompleteEventHandler(userIndexService_ServiceComplete);
userIndexService.send();

// create a new user
userCreateService = new HTTPService();
userCreateService.Url = “http://localhost:3000/users.xml”;
userCreateService.Method = “POST”;
userCreateService.ServiceComplete += new HttpServiceCompleteEventHandler(userCreateService_ServiceComplete);

// update a user, we will not be trapping the results
userUpdateService = new HTTPService();
userUpdateService.Method = “POST”;

// delete a user
userDeleteService = new HTTPService();
userDeleteService.Method = “POST”;
}

private void _userList_SelectionChanged(object sender, SelectionChangedEventArgs e) {
controls.DataContext = userList.SelectedItem as User;
}

private void userIndexService_ServiceComplete(HttpServiceCompleteEventArgs e) {
foreach (User user in User.users_from_xml(e.Response))
userListItems.Add(user);
}
private void userCreateService_ServiceComplete(HttpServiceCompleteEventArgs e) {
userListItems.Add(User.user_from_xml(e.Response));
}

private void createButton_Click(object sender, RoutedEventArgs e) {
userCreateService.send(String.Format(“{0}={1}&{2}={3}”, “user[name]“, userName.Text, “user[address]“, userAddress.Text));
}

private void updateButton_Click(object sender, RoutedEventArgs e) {
User _selectedUser = userList.SelectedItem as User;
userUpdateService.Url = “http://localhost:3000/users/” + _selectedUser.id.ToString() + “.xml”;
userUpdateService.send(String.Format(“{0}={1}&{2}={3}&{4}={5}”, “user[name]“, userName.Text, “user[address]“, userAddress.Text, “_method”, “PUT”));
userListItems[userList.SelectedIndex] = _selectedUser;
}

private void deleteButton_Click(object sender, RoutedEventArgs e) {
User _selectedUser = userList.SelectedItem as User;
userDeleteService.Url = “http://localhost:3000/users/” + _selectedUser.id.ToString() + “.xml”;
userDeleteService.send(String.Format(“{0}={1}”, “_method”, “DELETE”));
userListItems.Remove(_selectedUser);
}

}
}

To understand the specific parameters to the “send()” method of the HTTPService class you will need a little bit of understanding of how REST is implemented in Rails and how parameters are passed to a url, which is out of scope of this blog post.

Change Page.xaml to:

<UserControl x:Class=”TestFrontEnd.Page”
xmlns=”http://schemas.microsoft.com/client/2007″
xmlns x =”http://schemas.microsoft.com/winfx/2006/xaml”
Width=”400″ Height=”300″>
<Grid x:Name=”LayoutRoot” Background=”White”>
<StackPanel Orientation=”Vertical”>
<ListBox x:Name=”userList” ItemsSource=”{Binding}” DisplayMemberPath=”name” SelectionChanged=”_userList_SelectionChanged” Height=”200″/>
<StackPanel x:Name=”controls”>
<TextBox Text=”{Binding name, Mode=Twoway}” x:Name=”userName”/>
<TextBox Text=”{Binding address, Mode=Twoway}” x:Name=”userAddress”/>
</StackPanel>
<StackPanel Orientation=”Horizontal”>
<Button Content=”Create” x:Name=”createButton” Click=”createButton_Click”/>
<Button Content=”Update” x:Name=”updateButton” Click=”updateButton_Click”/>
<Button Content=”Delete” x:Name=”deleteButton” Click=”deleteButton_Click”/>
</StackPanel>
<TextBlock x:Name=”trace” />
</StackPanel>
</Grid>
</UserControl>

This is how it looks like now:

image

So this is full CRUD implementation using Silverlight as frontend.

This is not the most optimal way to implement CRUD it is very easy to understand. It also should be noted that I haven’t added error checking of any type in the code and there is a lot of code repetition. But I guess that could be improved upon further once the most simple scenario is implemented. My style of coding is “First make it work and then optimize it”, and as I have mentioned it before it is certainly not the most optimized way to code but it sure works )

One microsoft releases better databinding capabilities in controls and some simpler classes for HTTP based communication, this code would be much more simpler.

Full code for this aplication can be downloaded from:

  • Rails code
  • Silverlight code

  • Rails 2.0 deprecations

    April 17, 2008

    The Rails core team is cleaning up. That’s obviously a good thing, however it does leave us facing a kabillion deprecation warnings when running tests and whatnot.

    Unfortunately the official deprecations page appears to have been thrown together quickly after someone noticed that Rails 1.2 had been pushed out without anyone finishing the page that all deprecation warnings were referring to.

    So what does a smart Rails developer who wants to be ready for Rails 2.0 when that time comes around do? She reads on…

    end_form_tag is deprecated

    The old, deprecated way The new, supported way
    <%= start_form_tag %>
      ...stuff...
    <%= end_form_tag %>
    <% form_tag do %>
      ...stuff...
    <% end %>
    <%= form_remote_tag %>
      ...stuff...
    <%= end_form_tag %>
    <% form_remote_tag do %>
      ...stuff...
    <% end %>

    Object transactions are deprecated

    The old, deprecated way The new, supported way
    Model.transaction(foo) do
      ...stuff...
    end
    Model.transaction do
      ...stuff...
    end

    server_settings has been renamed smtp_settings

    The old, deprecated way The new, supported way
    ActionMailer::Base.server_settings = {
      :address  => 'my.smtp.srv'
    }
    ActionMailer::Base.smtp_settings = {
      :address  => 'my.smtp.srv'
    }

    start_form_tag is deprecated

    The old, deprecated way The new, supported way
    <%= start_form_tag %>
      ...stuff...
    <%= end_form_tag %>
    <% form_tag do %>
      ...stuff...
    <% end %>

    You called count([“field = ?”, value], nil)

    The old, deprecated way The new, supported way
    model_or_association.count(['field = ?', value])
    model_or_association.count(:conditions => ['field = ?', value])

    You’ve called image_path with a source that doesn’t include an extension

    The old, deprecated way The new, supported way
    <%= image_tag 'foo' %>
    <%= image_tag 'foo.png' %>

    Flex With ROR

    April 17, 2008

    Using Flex with Ruby on Rails

    The steps needed to create the Rails application using Flex

    Creating a new Flex project:

    Open Flex builder and create a new Flex project.

    image

    Leave all the options to default and click Finish. A blank project is now created for you.

    Add a List control to the default mxml file. It should look like:

    <?xml version=”1.0″ encoding=”utf-8″?>
    <mx:Application xmlns:mx=”http://www.adobe.com/2006/mxml” layout=”vertical”>
    <mx:List id=”userList” width=”200″ height=”200″/>
    </mx:Application>

    Now create a script tag inside the source and add a Bindable element to it:

    [Bindable]
    private var users:XMLListCollection = new XMLListCollection();

    I am using an XMLListCollection because I can easily add/remove elements from it.

    Now send request to the server and bind the result to the list box:

    First create a new HTTPService element:

    <mx:HTTPService id=“userIndexService” resultFormat=“e4x” result=“userIndexServiceResult(event)” url=“http://localhost:3000/users.xml”/>

    and handle its result:

    private function userIndexServiceResult(event:ResultEvent):void{
    for each(var xml:XML in event.result.user as XMLList){
    users.addItem(xml);
    }
    }

    To invoke this service we need to call its “send()” method with appropriate paramater, which in this case are none.

    So the code now looks like:

    <?xml version=”1.0″ encoding=”utf-8″?>
    <mx:Application xmlns:mx=”http://www.adobe.com/2006/mxml” layout=”vertical” initialize=”sendServiceRequest(event)”>
    <mx:Script>
    <![CDATA[
    import mx.rpc.events.ResultEvent;
    import mx.collections.XMLListCollection;
    [Bindable]
    private var users:XMLListCollection = new XMLListCollection();
    
    private function sendServiceRequest(event:Event):void{
    userIndexService.send();
    }
    private function userIndexServiceResult(event:ResultEvent):void{
    for each(var xml:XML in event.result.user as XMLList){
    users.addItem(xml);
    }
    }
    ]]>
    </mx:Script>
    <mx:HTTPService id=”userIndexService” resultFormat=”e4x” result=”userIndexServiceResult(event)” url=”http://localhost:3000/users.xml”/>
    <mx:List dataProvider=”{users}” id=”userList” width=”200″ height=”200″ labelField=”name”/>
    </mx:Application>

    And the output looks like:

    image

    Notice that we are sending the index request in the initialize method of the application.

    Now to add controls which show the currently selected element. Its really easy. Just add the folowwing to the code and DataBinding will do the rest:

    <mx:HBox>
    <mx:Label text=”Name” width=”50″/>
    <mx:TextInput text=”{userList.selectedItem.name}” width=”150″ id=”userName”/>
    </mx:HBox>
    <mx:HBox>
    <mx:Label text=”Address” width=”50″/>
    <mx:TextInput text=”{userList.selectedItem.address}” width=”150″ id=”userAddress”/>
    </mx:HBox>

    Now it loooks like:

    image

    Implementing the full CRUD:

    Now we need to add the other three HTTPServices.

    <mx:HTTPService id=”userIndexService” resultFormat=”e4x” result=”userIndexServiceResult(event)” url=”http://localhost:3000/users.xml”/>
    <mx:HTTPService id=”userCreateService” resultFormat=”e4x” result=”userCreateServiceResult(event)” method=”POST” url=”http://localhost:3000/users.xml”/>
    <mx:HTTPService id=”userUpdateService” resultFormat=”e4x” method=”POST”/>
    <mx:HTTPService id=”userDeleteService” resultFormat=”e4x” method=”POST”/>

    And their corresponding callbacks.

    private function userCreateServiceResult(event:ResultEvent):void{
    users.addItem(event.result as XML);
    }

    Some controls to invoke these services:

    <mx:HBox>
    <mx:Button label=”Create” id=”createUser” click=”sendServiceRequest(event)”/>
    <mx:Button label=”Update” id=”updateUser” click=”sendServiceRequest(event)”/>
    <mx:Button label=”Delete” id=”deleteUser” click=”sendServiceRequest(event)”/>
    </mx:HBox>

    And their event handlers (just one in this case):

    private function sendServiceRequest(event:Event):void{
    if(event.target.id == ‘createUser’){
    userCreateService.send({‘user[name]‘: userName.text, ‘user[address]‘: userAddress.text});
    }else if(event.target.id == ‘updateUser’){
    userUpdateService.url = ‘http://localhost:3000/users/’+ userList.selectedItem.id +‘.xml’;
    userUpdateService.send({‘user[name]‘: userName.text, ‘user[address]‘: userAddress.text, _method: ‘put’});
    users[userList.selectedIndex].name = userName.text;
    users[userList.selectedIndex].address = userAddress.text;
    }else if(event.target.id == ‘deleteUser’){
    userDeleteService.url = ‘http://localhost:3000/users/’+ userList.selectedItem.id +‘.xml’;
    userDeleteService.send({_method: ‘delete’});
    users.removeItemAt(userList.selectedIndex);
    }else{
    userIndexService.send();
    }
    }

    Little bit of knowledge of how REST is implemented in Rails is required to understand the parameters to the “send()” method of HTTPService class is required, which is out of scope of this blog post.

    The TestFrontEnd.mxml should now have the folowwing code:

    <?xml version=”1.0″ encoding=”utf-8″?>
    <mx:Application xmlns:mx=”http://www.adobe.com/2006/mxml” layout=”vertical” initialize=”sendServiceRequest(event)”>
    <mx:Script>
    <![CDATA[
    import mx.collections.XMLListCollection;
    import mx.controls.Alert;
    import mx.rpc.events.ResultEvent;
    import mx.collections.ArrayCollection;
    [Bindable]
    private var users:XMLListCollection = new XMLListCollection();
    
    private function sendServiceRequest(event:Event):void{
    if(event.target.id == ‘createUser’){
    userCreateService.send({’user[name]‘: userName.text, ‘user[address]‘: userAddress.text});
    }else if(event.target.id == ‘updateUser’){
    userUpdateService.url = ‘http://localhost:3000/users/’+ userList.selectedItem.id +’.xml’;
    userUpdateService.send({’user[name]‘: userName.text, ‘user[address]‘: userAddress.text, _method: ‘put’});
    users[userList.selectedIndex].name = userName.text;
    users[userList.selectedIndex].address = userAddress.text;
    }else if(event.target.id == ‘deleteUser’){
    userDeleteService.url = ‘http://localhost:3000/users/’+ userList.selectedItem.id +’.xml’;
    userDeleteService.send({_method: ‘delete’});
    users.removeItemAt(userList.selectedIndex);
    }else{
    userIndexService.send();
    }
    }
    
    private function userIndexServiceResult(event:ResultEvent):void{
    for each(var xml:XML in event.result.user as XMLList){
    users.addItem(xml);
    }
    }
    private function userCreateServiceResult(event:ResultEvent):void{
    users.addItem(event.result as XML);
    }
    ]]>
    </mx:Script>
    
    <mx:HTTPService id=”userIndexService” resultFormat=”e4x” result=”userIndexServiceResult(event)” url=”http://localhost:3000/users.xml”/>
    <mx:HTTPService id=”userCreateService” resultFormat=”e4x” result=”userCreateServiceResult(event)” method=”POST” url=”http://localhost:3000/users.xml”/>
    <mx:HTTPService id=”userUpdateService” resultFormat=”e4x” method=”POST”/>
    <mx:HTTPService id=”userDeleteService” resultFormat=”e4x” method=”POST”/>
    
    <mx:List dataProvider=”{users}” id=”userList” width=”200″ height=”200″ labelField=”name”/>
    
    <mx:HBox>
    <mx:Label text=”Name” width=”50″/>
    <mx:TextInput text=”{userList.selectedItem.name}” width=”150″ id=”userName”/>
    </mx:HBox>
    <mx:HBox>
    <mx:Label text=”Address” width=”50″/>
    <mx:TextInput text=”{userList.selectedItem.address}” width=”150″ id=”userAddress”/>
    </mx:HBox>
    <mx:HBox>
    <mx:Button label=”Create” id=”createUser” click=”sendServiceRequest(event)”/>
    <mx:Button label=”Update” id=”updateUser” click=”sendServiceRequest(event)”/>
    <mx:Button label=”Delete” id=”deleteUser” click=”sendServiceRequest(event)”/>
    </mx:HBox>
    
    </mx:Application>

    This is the end result:

    image

    As I mentioned in my last blog post it is not the best way to make this application as there is no error handling. But I think this is the simplest way to make this application.

    You also might have noticed Flex requires a lot less lines of code as compared to Silverlight. But that is also dependent on my coding approach.

    Full code for this application can be downloaded from:


    Rails 2.0

    December 5, 2007

     

    Rails 2.0

    Behold, behold, Rails 2.0 is almost here. But before we can slap on the final stamp, we’re going to pass through a couple of trial release phases. The first is this preview release, which allows you to sample the goodies in their almost finished state.

    We might change a few things or add something else, but by and large, this is how Rails 2.0 is going to look and feel. After this release have had a chance to be tried out, we’re going to move to a release candidate or two (or three, depending on how many we need). Then, the final release.

    Before the release of 2.0, we’re also going to be putting out 1.2.4, which will include a variety of bug fixes and the last deprecation warnings to get you ready for upgrading an existing application to 2.0 standards.

    Enough about process. Let me tell you a little bit about what’s new in Rails 2.0:

    Action Pack: Resources

    This is where the bulk of the action for 2.0 has gone. We’ve got a slew of improvements to the RESTful lifestyle. First, we’ve dropped the semicolon for custom methods instead of the regular slash. So /people/1;edit is now /people/1/edit. We’ve also added the namespace feature to routing resources that makes it really easy to confine things like admin interfaces:

    map.namespace(:admin) do |admin|
    
      admin.resources :products,
    
        :collection => { :inventory => :get },
    
        :member     => { :duplicate => :post },
    
        :has_many   => [ :tags, :images, :variants ]
    
    end

    Which will give you named routes like inventory_admin_products_url and admin_product_tags_url. To keep track of this named routes proliferation, we’ve added the “rake routes” task, which will list all the named routes created by routes.rb.

    We’ve also instigated a new convention that all resource-based controllers will be plural by default. This allows a single resource to be mapped in multiple contexts and still refer to the same controller. Example:

    
    
      # /avatars/45 => AvatarsController#show
    
      map.resources :avatars  # /people/5/avatar => AvatarsController#show
    
      map.resources :people, :has_one => :avatar

    Action Pack: Multiview

    Alongside the improvements for resources come improvements for multiview. We already have #respond_to, but we’ve taken it a step further and made it dig into the templates. We’ve separated the format of the template from its rendering engine. So show.rhtml now becomes show.html.erb, which is the template that’ll be rendered by default for a show action that has declared format.html in its respond_to. And you can now have something like show.csv.erb, which targets text/csv, but also uses the default ERB renderer.

    So the new format for templates is action.format.renderer. A few examples:

    • show.erb: same show template for all formats
    • index.atom.builder: uses the Builder format, previously known as rxml, to render an index action for the application/atom+xml mime type
    • edit.iphone.haml: uses the custom HAML template engine (not included by default) to render an edit action for the custom Mime::IPHONE format

    Speaking of the iPhone, we’ve made it easier to declare “fake” types that are only used for internal routing. Like when you want a special HTML interface just for an iPhone. All it takes is something like this:

    
    
      # should go in config/initializers/mime_types.rb
    
      Mime.register_alias "text/html", :iphone  class ApplicationController < ActionController::Base
    
        before_filter :adjust_format_for_iphone
    
    private
    
          def adjust_format_for_iphone
    
            if request.env["HTTP_USER_AGENT"] && request.env["HTTP_USER_AGENT"][/(iPhone|iPod)/]
    
              request.format = :iphone
    
            end
    
          end
    
      end
    
    class PostsController < ApplicationController
    
        def index
    
          respond_to do |format|
    
            format.html   # renders index.html.erb
    
            format.iphone # renders index.iphone.erb
    
          end
    
        end
    
      end

    You’re encouraged to declare your own mime-type aliases in the config/initializers/mime_types.rb file. This file is included by default in all new applications.

    Action Pack: Record identification

    Piggy-backing off the new drive for resources are a number of simplifications for controller and view methods that deal with URLs. We’ve added a number of conventions for turning model classes into resource routes on the fly. Examples:

    
    
      # person is a Person object, which by convention will
    
      # be mapped to person_url for lookup
    
      redirect_to(person)
    
      link_to(person.name, person)
    
      form_for(person)
    
    

    Action Pack: HTTP Loving

    As you might have gathered, Action Pack in Rails 2.0 is all about getting closer with HTTP and all its glory. Resources, multiple representations, but there’s more. We’ve added a new module to work with HTTP Basic Authentication, which turns out to be a great way to do API authentication over SSL. It’s terribly simple to use. Here’s an example (there are more in ActionController::HttpAuthentication):

    
    
      class PostsController < ApplicationController
    
        USER_NAME, PASSWORD = "dhh", "secret"     before_filter :authenticate, :except => [ :index ]
    
    def index
    
          render :text => "Everyone can see me!"
    
        end
    
    def edit
    
          render :text => "I'm only accessible if you know the password"
    
        end
    
    private
    
          def authenticate
    
            authenticate_or_request_with_http_basic do |user_name, password|
    
              user_name == USER_NAME && password == PASSWORD
    
            end
    
          end
    
      end

    We’ve also made it much easier to structure your JavaScript and stylesheet files in logical units without getting clobbered by the HTTP overhead of requesting a bazillion files. Using javascript_include_tag(:all, :cache => true) will turn public/javascripts/.js into a single public/javascripts/all.js file in production, while still keeping the files separate in development, so you can work iteratively without clearing the cache.

    Along the same lines, we’ve added the option to cheat browsers who don’t feel like pipelining requests on their own. If you set ActionController::Base.asset_host = “assets%d.example.com”, we’ll automatically distribute your asset calls (like image_tag) to asset1 through asset4. That allows the browser to open many more connections at a time and increases the perceived speed of your application.

    Action Pack: Security

    Making it even easier to create secure applications out of the box is always a pleasure and with Rails 2.0 we’re doing it from a number of fronts. Most importantly, we now ship we a built-in mechanism for dealing with CRSF attacks. By including a special token in all forms and Ajax requests, you can guard from having requests made from outside of your application. All this is turned on by default in new Rails 2.0 applications and you can very easily turn it on in your existing applications using ActionController::Base.protect_from_forgery (see ActionController::RequestForgeryProtection for more).

    We’ve also made it easier to deal with XSS attacks while still allowing users to embed HTML in your pages. The old TextHelper#sanitize method has gone from a black list (very hard to keep secure) approach to a white list approach. If you’re already using sanitize, you’ll automatically be granted better protection. You can tweak the tags that are allowed by default with sanitize as well. See TextHelper#sanitize for details.

    Finally, we’ve added support for HTTP only cookies. They are not yet supported by all browsers, but you can use them where they are.

    Action Pack: Exception handling

    Lots of common exceptions would do better to be rescued at a shared level rather than per action. This has always been possible by overwriting rescue_action_in_public, but then you had to roll out your own case statement and call super. Bah. So now we have a class level macro called rescue_from, which you can use to declaratively point certain exceptions to a given action. Example:

    
    
      class PostsController < ApplicationController
    
        rescue_from User::NotAuthorized, :with => :deny_access    protected
    
          def deny_access
    
            ...
    
          end
    
      end

    Action Pack: Miscellaneous

    Also of note is AtomFeedHelper, which makes it even simpler to create Atom feeds using an enhanced Builder syntax. Simple example:

    
    
      # index.atom.builder:
    
      atom_feed do |feed|
    
        feed.title("My great blog!")
    
        feed.updated((@posts.first.created_at))    for post in @posts
    
          feed.entry(post) do |entry|
    
            entry.title(post.title)
    
            entry.content(post.body, :type => 'html')
    
    entry.author do |author|
    
              author.name("DHH")
    
            end
    
          end
    
        end
    
      end

    We’ve made a number of performance improvements, so asset tag calls are now much cheaper and we’re caching simple named routes, making them much faster too.

    Finally, we’ve kicked out in_place_editor and autocomplete_for into plugins that live on the official Rails SVN.

    Active Record: Performance

    Active Record has seen a gazillion fixes and small tweaks, but it’s somewhat light on big new features. Something new that we have added, though, is a very simple Query Cache, which will recognize similar SQL calls from within the same request and return the cached result. This is especially nice for N+1 situations that might be hard to handle with :include or other mechanisms. We’ve also drastically improved the performance of fixtures, which makes most test suites based on normal fixture use be 50-100% faster.

    Active Record: Sexy migrations

    There’s a new alternative format for declaring migrations in a slightly more efficient format. Before you’d write:

    create_table :people do |t|
    
      t.column, "account_id",  :integer
    
      t.column, "first_name",  :string, :null => false
    
      t.column, "last_name",   :string, :null => false
    
      t.column, "description", :text
    
      t.column, "created_at",  :datetime
    
      t.column, "updated_at",  :datetime
    
    end

    Now you can write:

    create_table :people do |t|
    
      t.integer :account_id
    
      t.string  :first_name, :last_name, :null => false
    
      t.text    :description
    
      t.timestamps
    
    end

    Active Record: XML in, JSON out

    Active Record has supported serialization to XML for a while. In 2.0 we’ve added deserialization too, so you can say Person.new.from_xml(“
    David“) and get what you’d expect. We’ve also added serialization to JSON, which supports the same syntax as XML serialization (including nested associations). Just do person.to_json and you’re ready to roll.

    Active Record: Shedding some weight

    To make Active Record a little leaner and meaner, we’ve removed the acts_as_XYZ features and put them into individual plugins on the Rails SVN repository. So say you’re using acts_as_list, you just need to do ./script/plugin install acts_as_list and everything will move along like nothing ever happened.

    A little more drastic, we’ve also pushed all the commercial database adapters into their own gems. So Rails now only ships with adapters for MySQL, SQLite, and PostgreSQL. These are the databases that we have easy and willing access to test on. But that doesn’t mean the commercial databases are left out in the cold. Rather, they’ve now been set free to have an independent release schedule from the main Rails distribution. And that’s probably a good thing as the commercial databases tend to require a lot more exceptions and hoop jumping on a regular basis to work well.

    The commercial database adapters now live in gems that all follow the same naming convention: activerecord-XYZ-adapter. So if you gem install activerecord-oracle-adapter, you’ll instantly have Oracle available as an adapter choice in all the Rails applications on that machine. You won’t have to change a single line in your applications to take use of it.

    That also means it’ll be easier for new database adapters to gain traction in the Rails world. As long as you package your adapter according to the published conventions, users just have to install the gem and they’re ready to roll.

    Active Record: with_scope with a dash of syntactic vinegar

    ActiveRecord::Base.with_scope has gone protected to discourage people from misusing it in controllers (especially in filters). Instead, it’s now encouraged that you only use it within the model itself. That’s what it was designed for and where it logically remains a good fit. But of course, this is all about encouraging and discouraging. If you’ve weighed the pros and the cons and still want to use with_scope outside of the model, you can always call it through .send(:with_scope).

    ActionWebService out, ActiveResource in

    It’ll probably come as no surprise that Rails has picked a side in the SOAP vs REST debate. Unless you absolutely have to use SOAP for integration purposes, we strongly discourage you from doing so. As a naturally extension of that, we’ve pulled ActionWebService from the default bundle. It’s only a gem install actionwebservice away, but it sends an important message none the less.

    At the same time, we’ve pulled the new ActiveResource framework out of beta and into the default bundle. ActiveResource is like ActiveRecord, but for resources. It follows a similar API and is configured to Just Work with Rails applications using the resource-driven approach. For example, a vanilla scaffold will be accessible by ActiveResource.

    ActiveSupport

    There’s not all that much new in ActiveSupport. We’ve a host of new methods like Array#rand for getting a random element from an array, Hash#except to filter down a hash from undesired keys and lots of extensions for Date. We also made testing a little nicer with assert_difference. Short of that, it’s pretty much just fixes and tweaks.

    Action Mailer

    This is a very modest update for Action Mailer. Besides a handful of bug fixes, we’ve added the option to register alternative template engines and assert_emails to the testing suite, which works like this:

    1. Assert number of emails delivered within a block: assert_emails 1 do post :signup, :name => ‘Jonathan’ end

    Rails: The debugger is back

    To tie it all together, we have a stream of improvements for Rails in general. My favorite amongst these is the return of the breakpoint in form of the debugger. It’s a real debugger too, not just an IRB dump. You can step back and forth, list your current position, and much more. It’s all coming from the gracious note of the ruby-debug gem. So you’ll have to install that for the new debugger to work.

    To use the debugger, you just install the gem, put “debugger” somewhere in your application, and then start the server with—debugger or -u. When the code executes the debugger command, you’ll have it available straight in the terminal running the server. No need for script/breakpointer or anything else. You can use the debugger in your tests too.

    Rails: Clean up your environment

    Before Rails 2.0, config/environment.rb files every where would be clogged with all sorts of one-off configuration details. Now you can gather those elements in self-contained files and put them under config/initializers and they’ll automatically be loaded. New Rails 2.0 applications ship with two examples in form of inflections.rb (for your own pluralization rules) and mime_types.rb (for your own mime types). This should ensure that you need to keep nothing but the default in config/environment.rb.

    Rails: Easier plugin order

    Now that we’ve yanked out a fair amount of stuff from Rails and into plugins, you might well have other plugins that depend on this functionality. This can require that you load, say, acts_as_list before your own acts_as_extra_cool_list plugin in order for the latter to extend the former.

    Before, this required that you named all your plugins in config.plugins. Major hassle when all you wanted to say was “I only care about acts_as_list being loaded before everything else”. Now you can do exactly that with config.plugins = [ :acts_as_list, :all ].

    And hundreds upon hundreds of other improvements

    What I’ve talked about above is but a tiny sliver of the full 2.0 package. We’ve got literally hundreds of bug fixes, tweaks, and feature enhancements crammed into Rails 2.0. All this coming off the work of tons of eager contributors working tirelessly to improve the framework in small, but important ways.

    I encourage you to scourger the CHANGELOGs and learn more about all that changed.

    So how do I upgrade?

    If you want to move your application to Rails 2.0, you should first move it to Rails 1.2.3. That’ll include deprecation warnings for most everything we yanked out in 2.0. So if your application runs fine on 1.2.3 with no deprecation warnings, there’s a good chance that it’ll run straight up on 2.0. Of course, if you’re using, say, pagination, you’ll need to install the classic_pagination plugin. If you’re using Oracle, you’ll need to install the activerecord-oracle-adapter gem. And so on and so forth for all the extractions.

    To install the preview release through gems, do:

    gem install rails --source http://gems.rubyonrails.org

    To try it from an SVN tag, use:

    rake rails:freeze:edge TAG=rel_2-0-0_PR

    We’ll also be putting out Rails 1.2.4 shortly which will include a few more deprecations to warn you in time for 2.0.

    In any case, as I explained in the beginning, this is a preview release. Use it to get a feel for 2.0. See where your currently application might need tweaks. And try creating a new application from scratch to see the new defaults. In a few weeks we’ll get on with the release candidates.

    Thanks to everyone who’ve been involved with the development of Rails 2.0. We’ve been working on this for more than six months and it’s great finally to be able to share it with a larger audience. Enjoy!

    Posted in Releases | 135 comments

    Comments

    1. DHH on 30 Sep 23:24:
      If you know of any blogging done on Rails 2.0 features, please comment with links in this thread.
    2. Joe Ruby on 30 Sep 23:59:
      “So /people/1;edit is now /people/1/edit”I missed TFM explaining why the newish semi-colon for custom methods is being reverted back. Briefly searching the forums I found:“Doesn’t work with page caching, safari has bugs with authentication with urls with semi colons in it. Various libraries (like mongrel) mistakenly consider ; to be part of the query string.”
    3. J. Pablo Fernandez on 01 Oct 00:03:
      When is the final stable version expected to be released?
    4. donnacha on 01 Oct 00:03:
      So … when will the updated edition of “Agile Web Development with Rails” be hitting the shelves?
    5. Nate on 01 Oct 00:06:
      Great stuff. The query cache rocks. If anyone wants to use it on their Rails 1.2.x apps without upgrading to edge I pulled it into a plugin
    6. Andy on 01 Oct 00:19:
      Thanks for all the hard work! Can’t wait to try it out.
    7. DHH on 01 Oct 00:48:
      Pablo, the first two paragraphs of this announcement is as good as it’ll get for a target right now.donnacha, the changes in 2.0 are in some ways less overall disruptive than the changes in 1.2. So I wouldn’t expect (or think we need) an immediate update to that book.
    8. Julik on 01 Oct 01:28:
      Ironically, it’s the first releas of Rails where I feel like parting ways with the framework. I’m curious what will come next though, so I will stay some more.
    9. Tom on 01 Oct 01:40:
      Quick note: I just pulled rel_2-0-0_PR. It still seems to include actionwebservice and doesn’t fetch activeresource.
    10. Tom on 01 Oct 01:45:
      Ok, ignore previous comment: I had to run the rails:freeze:edge twice. The first time, it still used settings from version 1.2. Tom
    11. Luke Melia on 01 Oct 02:21:
      Looks great.Is there a decent way to get slashes instead of semi-colons for RESTful routes in 1.2.x for those of us about to launch apps?
    12. Jeremy Kemper on 01 Oct 02:50:
      Luke, the forthcoming 1.2.4 release will introduce the new routing style and deprecate the old to ease the transition to 2.0.
    13. MilesZS on 01 Oct 02:53:
      Mr Melia:I have been using this with success: http://push.cx/2007/rails-semicolons-out-slashes-inHope that helps.
    14. pyodor on 01 Oct 03:44:
      can’t wait to try this :)
    15. Chu Yeow on 01 Oct 03:55:
      Dugg this :) -> http://digg.com/software/Rails_2_0_Preview_Release_availableMy favorite is the JSON changes, especially that only valid JSON is emitted now (all object keys are quoted now), though it’s not mentioned in this blog post.
    16. Manu on 01 Oct 05:26:
      where can I get the changelog?
    17. rick on 01 Oct 05:52:
      You can get the changelogs for the individual components: activerecord, actionpack, etc.
    18. Kristof on 01 Oct 06:14:
      DHH, I’d be also interested in the book update (like many others I think).Years ago I got the first book but Rails improving that fast I lost my track completely in months following up the changes. Since that, I haven’t touched rails for over a year now. I’d like to give it a second spin but buying into the 1.2 book, I’m scared to make the same story happening again..Also, I’d love to read about more advanced topics like cluster-deployment, caching, capistrano, etc. Do you still suggest me buying into the 1.2-compatible version of the book? Honestly, a few months wait would be worth for me learning the most uptodate material. Thanks!
    19. Phil Thompson on 01 Oct 07:04:
      Just wanted to thank everyone for working so hard on the new release. I’ve been trying out ActiveResource and it’s so lightweight, so simple to use. Along with all the other enhancements this is really shaping up to be a great release and certainly fit to be called 2.0. Thanks again.
    20. Chetan Mittal on 01 Oct 07:35:
      WOW !!! The ActiveResource pick, Migrations and ActionPack changes are awesome. Thanks for the hard-work.
    21. http://www.botvector.net on 01 Oct 08:00:
      That is really good news!
    22. Spif on 01 Oct 08:38:

      Action Pack: Resources More way to use routes in creative ways. AKA more ways to slow your Rails App down.

      Action Pack: Record identification More useless ways to use slow, slow routes.

      What happened to “Rails 2 was going to be faster and smaller than 1.x, with significantly more code moved outside the core.” While plenty of code has moved out of the core, the core itself is larger and slower than before. Perhaps after 2.0 there will be time to do some much-needed cleanup.

    23. Lisa Seelye on 01 Oct 09:02:
      So where are the tests for the split off adapter gems?http://svn.rubyonrails.org/rails/adapters/ seems devoid of tests which kind of sucks cos I want to submit a patch!
    24. Garth on 01 Oct 09:08:
      The thing I like the most about this release is the break out of pieces into gems and plug-ins. Rails was starting to get bloated and much of the functionality offered by the framework wasn’t getting used in my projects. Great job on getting this release out so far.
    25. Pratik on 01 Oct 09:38:
      I had blogged about some simple steps to enable CSRF protection for your existing apps – http://m.onkey.org/2007/9/28/csrf-protection-for-your-existing-rails-application
    26. Peter on 01 Oct 09:38:
      Is there some documentation on why exactly with_scope is discouraged for filters?The scoped_access plugin uses with_scope extensively for just this purpose. I suppose you are saying this is bad practice. why?
    27. Skyblaze on 01 Oct 10:15:
      I think that a signifiacnt update to the AWDVR book is a must. And as other said it could be updated also with new things such as capistrano 2 and some advanced concepts and examples..
    28. Heiko on 01 Oct 10:43:
      Great news. Some notes about the security paragraph, click my name.
    29. Toño on 01 Oct 10:52:
      Great work guys!
    30. Pratik on 01 Oct 11:29:
      Peter : Check out post/comments at this post
    31. Sam on 01 Oct 11:35:
      You guys rock. I especially like the CSRF protection you put in.
    32. Matt on 01 Oct 11:55:
      Blogged my initial reaction, installing the 2.0PR gem now to give it a go and will post results of that.http://didcoe.id.au/archives/rails-20-the-release-is-near
    33. peanut on 01 Oct 12:48:
      So, I think it’s a great work. Rails becomes more cleaner, intelligent and faster (I think).
    34. Thibaud Guillaume-Gentil on 01 Oct 12:48:
      If you want to rename (svn move here) all your files with *.rhtml to *html.erb in one command line try this:for f in $(find . -name *.rhtml) ; do g=$(dirname $f)/$(basename $f .rhtml).html.erb ; svn mv $f $g ; doneEnjoy!
    35. nap on 01 Oct 13:11:
      Great work everyone. This is excellent. And thanks for nixing the semi in restful routes ;-) .
    36. Ryan on 01 Oct 13:41:

      Years ago I got the first book but Rails improving that fast I lost my track completely in months following up the changes. Since that, I haven’t touched rails for over a year now. I’d like to give it a second spin but buying into the 1.2 book, I’m scared to make the same story happening again..

      I agree. I have held off buying Agile 2.0 due to the changes in Edge. While the 1.1 to 1.2 transition included lots of new, better ways to do things and added to the framework, 2.0 seems to make much more fundamental changes in the day-to-day tasks. In other words, I’ve had to rewrite more code for this transition, though that may just be me.

      Otherwise, great work! Rails continues to impress me more and more!

    37. DHH on 01 Oct 14:16:
      spif, funny that both the examples you choose to highlight are ones that are actually much faster in Rails 2.0 than they were in Rails 1.2.3.Resources uses named routes and so does the new record identification. And named routes now do a lot of clever optimizations to be way faster than the regular url_for approach.So please get your facts straight before screaming murder.
    38. Spif on 01 Oct 14:47:
      DHH, sorry if my comment was a bit crude.It is great to see Rails maturing, simplifying and conforming to more small common practices (like the resources dropping semicolons from custom methods). Overall great effort, yet lacking IMO in one key feat: core performance.Let me rephrase my critique to something more constructive. While I do think the new features are useful and do speed things up, my personal feeling is that the core performance issues have not been addressed, yet bypassed by things like clever optimizations.So even though we use and admire the massive work in Rails, still hoping for renewed focus on performance.No offense meant and keep up the great work!
    39. Scott on 01 Oct 14:53:
      If I am to understand the multi-view, .rjs files would become .js.erb? If this is the case it doesn’t currently render the file automatically as if it were named <action>.rjs.
    40. Chris on 01 Oct 14:57:

      it’ll be easier for new database adapters to gain traction in the Rails world. As long as you package your adapter according to the published conventions, users just have to install the gem and they’re ready to roll.

      I worry though that this will lead to 30 different MySQL adapters, all claiming to be better than the rest. Will there be an official line of adapters or some kind of official adapter validation process?

    41. DHH on 01 Oct 14:57:
      Spif, this release has actually seen more attention paid to performance than any release since 1.0. We profiled Rails extensively and made a number of optimizations based on that (like caching asset tag file calls, the new BufferedLogger etc).We also benchmarked Rails against leaner alternatives, like Merb, and were much surprised to see that the difference wasn’t at all as big as expected (especially once you started doing real-world things, like rendering an ERB template instead of just doing a text-based “hello world”). And that things like alias_method_chain, which has gotten a lot of flak for supposedly being the end of the world slow, really didn’t make much of a difference.But I agree that we should continue to improve the performance of Rails. Just that this release is probably the wrong one to complain that we NEVER pay any attention to that ;)
    42. Chris on 01 Oct 15:02:
      PS: Oops! I didn’t mean to leave only a concern – Thanks for all the hard work. Can’t wait to try some of the new things. The new sexy migration syntax (that really should be the offical name) will save precious keystrokes and make a lot of sense!
    43. DHH on 01 Oct 15:13:
      Chris, there’ll only be 1 official Rails adapter per database. But it’ll be easier for people to create new adapters for databases we don’t already cover.
    44. Torsten on 01 Oct 16:03:
      Congratulations to the Rails team for continuing to shape such a great product for the next steps. I look forward to using all the cool features – only this speed of innovation will help to make Rails the basis for interesting web applications.Keep on the good work.
    45. Dan Croak on 01 Oct 16:12:
      Congrats to DHH, Rails Core, and all the contributors to Rails 2.0! Looking forward to getting my hands on it.When y’all did your profiling, did you use ruby-prof? Is that the recommended approach to profiling Rails apps? Would there be any advantage to adding a hypothetical script/profile that works with ruby-prof in the same manner that script/console interacts with irb and your Rails app?
    46. Roller8 on 01 Oct 16:27:
      I know I’m excited to implement this version! Any performance improvements are definitely high on my wish list also, but I’m still enjoying the development performance and appreciate all the great work of the Rails team!
    47. DHH on 01 Oct 16:36:
      Dan Croak, yes we used ruby-prof. And you point about a script that wraps that is good. We’ve been working with a prototype of that for a while. We’ll put it in the bundle shortly.
    48. Sam Granieri on 01 Oct 16:43:
      Thanks for getting 2.0 out in gem form in a preview release. I’ve been experimenting with thishttp://railstips.org/2007/5/31/even-edgier-than-edge-railsfor a while.
    49. Shane on 01 Oct 17:07:
      Congrats…http://everydayblog.net/2007/10/01/ror-20/
    50. ctran on 01 Oct 17:12:
      Just a minor correction on one of the examples, it’s Mime::Type.register_alias instead of Mime.register_alias.
    51. JTH on 01 Oct 17:40:
      Just curious, does this have anything to do with the upcoming release of Tiger? i.e. is there a push to get 2.0 included in 10.5?
    52. Jan on 01 Oct 17:51:
      Doinggem install rails—source http://gems.rubyonrails.orgthenrake rails:freeze:edge TAG=rel_2-0-0_PRgives meCannot find gem for Rails ~>2.0.0gem query—remote—source http://gems.rubyonrails.org/ lists 1.2.3.7707 as the latest rails version. Am I doing something wrong?
    53. JTH on 01 Oct 18:22:
      Leopard, I say. Leopard.
    54. AR on 01 Oct 19:24:
      I’m having the same problem as Jan. Installing the latest gem gives me 1.2.3.7707. Any body have any idea what’s up?
    55. Jim Lindley on 01 Oct 19:29:
      1.2.3.7707 is the same as 2.0 RC.Gems can only have version numbers, and this is the only way to get a 2.0 release out without calling it 2.0.0, which it isn’t.The 7707 part corresponds to the latest changeset, 7702 was the release tagged 2.0 RC, so you’re all set.
    56. jack dempsey on 01 Oct 20:03:
      just a tip to those mentioning things like “Ok, ignore previous comment: I had to run the rails:freeze:edge twice. The first time, it still used settings from version 1.2. Tom”Remember, when you run that, its using the current rails code on your computer to pull down updates. Once you have that update version of rails, you can then run the command again to get all the updates IT knows about.Make sense? (I got used to doing this two time thing when first playing with ActiveResource when it hit edge).BTW, much thanks to the core team for all the work!
    57. jeem on 01 Oct 21:13:
      In ActiveResource, as of rel_2-0-0_PR, “MyRestDude.find :all” still raises an error. “undefined method `collect!’ for #<hash:0x3650c98>”. See http://dev.rubyonrails.org/ticket/8798.Maybe find(:all) isn’t important to many Rest consumers, but it seems like a big bug to leave in 2.0.
    58. Glenn Rempe on 01 Oct 21:55:
      Great job on Rails 2.0! Looking forward to putting it to use.Regarding getting your existing 1.2.3 application view files in line with the new naming standard for Rails 2.0.I found this script to be much more complete in the task of renaming all of your view files to be rails 2.0 compliant (e.g. .rhtml => *.html.erb, etc.). It handles a number of different file types and won’t incorrectly rename files under non app/views/ dirs when run carelessly like the less comprehensive script provided above which happily renamed all of my rails and plugins files too.I didn’t write it (someone named Bret did). I am just linking to it as it did the trick very well for me. YMMV.Copy it to the file lib/tasks/views.rake and run ‘rake views:rename’(Oh, and modify it to use something other than SVN if you use Git like I do.) We shouldn’t be making assumptions about what version control system people are using in our scripts :-) Script is here: http://pastie.caboo.se/84585.txtGlenn
    59. Felipe Giotto on 01 Oct 21:59:
      Great post! Now I finally found out most of the benefits and features from Rails 2.0 in one single place!Felipe Luiz C. Giotto www.inovare.net
    60. Sergio O on 01 Oct 22:31:
      Great to hear the news for 2.0 ! So would 2.0 be included in OS X?Looking forward to it !
    61. dan chak on 01 Oct 22:34:
      From what I’ve read, the ActiveRecord query cache is only active from the start of an action’s execution to the end. So it sounds like it’s a band-aid for bad code that makes the same request over and over within a single action. (Why would anyone do that?)I’d rather see real database-level bind variables implemented in ActiveRecord (as opposed to performing the binding in Ruby). Then even well written code will get a performance boost. :-) Any chance we’ll see that in 2.1?
    62. Giorgio Clavelli on 01 Oct 23:33:
      …we’re going to move to a release candidate or two (or three, depending on how many we need). Then, the final release.Firstly, thanks for this amazing framework. I’m relatively new to it, but I really enjoying the whole approach to web app development it promote. I’ve just one question, when do you think the final release may be available?Thanks
    63. Brian Doll on 01 Oct 23:48:
      Any word on support for foreign keys in ActiveRecord? With a very common plugin available(http://www.redhillonrails.org/#foreign_key_migrations), I was hoping to see it rolled into core in v2.
    64. AkitaOnRails on 02 Oct 00:01:
      Hey, great release. I was running Mephisto on Rails 1.2.3 and I decided to test 2.0PR. Turns out that I had to do very few adaptations on Mephisto and a couple of plugins and I already cap deployed my blog. It is online, production mode, running under 2.0PR. And so far it feels smooth as ever.Great release, congratulations!
    65. Mike Bailey on 02 Oct 01:44:
      Congratulations on the release and thanks for the excellent summary.
    66. carlity on 02 Oct 02:37:
      Obviously rails 2.0 won’t be included in Leopard, OSX 10.5 is coming out in a couple of weeks.
    67. Gary Castillo G on 02 Oct 05:06:
      Thanks for all the hard work.Will we have composite primary keys on AR some day?Best regards.
    68. WildPalms on 02 Oct 05:39:
      JTH, I think you mean Leopard. Tiger = 10.4, while Leopard = 10.5.
    69. deman on 02 Oct 07:55:
      rails 2.0 preview = rails 1.2.3.7707??
    70. cengiz on 02 Oct 09:02:
      I am very happy. :)
    71. Anthony Green on 02 Oct 10:22:
      The change to with_scope might break its usage in association declarations.I’ve been using the technique documented by Josh Susserhttp://blog.hasmanythrough.com/2006/08/19/magic-join-model-creationto magically create join models.Now I’m getting a protected method error in my tests.
    72. Aquiles on 02 Oct 12:51:
      Any way to have Rails 2.0 and 1.2.3 on same machine???
    73. Paul Pagel on 02 Oct 14:29:
      Aquiles, yes you can either have rails in your /vendor/plugins dir or install the gems as localgems to the project.
    74. nicolash on 02 Oct 20:37:
      a label-helper is included but sadly not used in scaffold. Tiny thing but I never understood why it was not included before. Same goes for fieldset (with legend)
    75. billd on 02 Oct 20:51:
      I haven’t read much about scaling. Was there anything that addressed multi-threading or multiple databases?DHH: I’ve been reading Ryan’s blog which has some good details about Edge Rails changes. http://ryandaigle.com/Thank you developers! Can’t wait to check it out.
    76. polypus on 02 Oct 23:58:
      i’m getting an error when i try to boot up script/server both with the gem and the freeze:edge versions.`const_missing’: uninitialized constant CGI::Session::CookieStoreanybody else get that?
    77. Rob on 03 Oct 02:27:
      When will Rails finally get documentation without being forced to buy a $20 book?
    78. Carl on 03 Oct 06:56:
      polypus: No, but this is what I get when running mongrel on my server when I try to run some of the web applications with a freezed 2.0 preview rails:vendor/rails/activerecord/lib/../../activesupport/lib/active_support/dependencies.rb:478:in `const_missing’: uninitialized constant ActionController::Caching::Sweeper::Reloadable (NameError)
    79. polypus on 03 Oct 12:09:
      carl, weird, looks similar. you should post your problem up on my thread at rubyforum. i posted yesterday but have no responses yet. strength in numbers :) http://www.railsforum.com/viewtopic.php?id=11608
    80. Dan Croak on 03 Oct 14:38:
      DHH et al.,Are there any changes or innovations in testing?RSpec seems to be gaining momentum (although I haven’t used it). There’s plenty of support for Mocha and Flexmock. I know people are extending Test::Unit with methods like asserts_sends_email and should_be_restful.What are the opinions of Rails 2.0 on advancing great testing practices by Rails developers?
    81. spyros on 03 Oct 16:47:
      First Thanx to the CoreTeam and congratulations for another great release.About sexy migrations… http://errtheblog.com/post/2381 features a plugin with the same title which makes things even sexier (!)by turningt.integer :account_idintoforeign_key :accountnice!
    82. DHH on 03 Oct 17:36:
      Rob, if you don’t like what’s currently available for free (API docs, wikis, blog posts) and you don’t want to pay what’s available commercially (books, screencasts), then you have all the power in the world to come up with an alternative and give it away for free. Go for it!Dan, there’s a handful of new assertions, like assert_email and assert_difference_of. There’s also much faster fixtures. And you don’t have to explicitly declare them any more. I think those are some nice steps forward.And it’s really easy to add your own sugar on top. Whether you want to install mocha or rspec. I don’t think those things necessarily belongs in core.
    83. Diego on 04 Oct 04:27:
      Rails 2.x should be more faster with Ruby 2.0 aka YARV right?
    84. Ted on 04 Oct 04:52:
      David—Are you guys interested in taking ActiveResource the RDF route? I’m about finished with an acts_as_rdf plugin that gives ActiveResource objects a to_rdf method. Once that’s done it wouldn’t be too hard to make a from_rdf (except that to_rdf only requires the Builder for RDFXML, but from_rdf would want to take into account parsing any one of a number of RDF formats..)
    85. blj on 04 Oct 09:04:
      Currently I use a very simple hack to keep the plugin dependency load order.I just name the folders like migration:00-money-1.7.1 01-google4r-checkoutworks and simple to change.
    86. DHH on 04 Oct 16:44:
      Ted, I think that would probably be a plugin. But sounds cool. Do put it out there.
    87. Donnie on 04 Oct 17:02:
      I know a definitive answer is not plausible, but will Rails 2.0 run on Ruby 2.0? Has there been any sort of testing in this direction?
    88. DHH on 04 Oct 21:26:
      Donnie, Jeremy has done a good amount of work for 1.9 compatibility. But it really doesn’t matter. As soon as Ruby 2.0 is getting ready for release, we’ll make sure that there’s a Rails version that runs it.
    89. Alex Egg on 04 Oct 23:50:
      Proper JSON encoding by default!
    90. versionboy_ms@yahoo.com on 05 Oct 07:36:
      hellosend me computer booksthanking you
    91. Arjun on 05 Oct 09:06:
      Hi David, have been yours for quite some time. So first congrats to u,core team and others u helped. I liked the migration thing. Made it much simpler. Also that is Rails is going the REST way.
    92. Dipesh on 06 Oct 08:21:
      Hey! is resource_scaffold missing from Rails 2.0 or is there is alternative?
    93. Bala Paranj on 07 Oct 07:47:
      Here is notes on how I used RESTful authentication plugin with Rails 2.0 preview release:http://bparanj.blogspot.com/2007/10/restful-authentication-with-rails-20.html
    94. Mike Bailey on 07 Oct 16:10:
      Dipesh, scaffold_resource is now scaffold.
    95. Balls Itchy on 07 Oct 19:29:
      Very cool, core team!
    96. Adz on 08 Oct 23:49:
      Dipesh: Seems as though ‘scaffold’ does what ‘resource_scaffold’ used to…. I guess it’s now the (only) default.
    97. ~SupaSharp~ on 09 Oct 12:40:
      I love RUBY!
    98. mr_roboto on 09 Oct 16:48:
      any word on cookie based sessions? been hearing about these in edge rails and becoming the new default. is this making it in the 2.0 release?
    99. Andrew on 10 Oct 14:55:
      Anybody else getting an error when they try and upgrade to the 2.0 PR using gems ? Anyway, great release guys. Keep up the good work.I am getting the following error: > gem install rails—source http://gems.rubyonrails.org Install required dependency activesupport? [Yn] Y Install required dependency builder? [Yn] Y ERROR: While executing gem … (Gem::GemNotFoundException) Could not find builder (~> 2.1.2) in the repository
    100. Andrew on 10 Oct 16:06:
      For some reason I need to install the builder gem separately before installing the 2.0 PR gem.
    101. Sven on 11 Oct 00:48:
      I’ve updated my gems to 1.2.4.7794, but I’m having trouble getting certain plugins to pass testing. In particular, with acts_as_attachment and acts_as_paranoid I’m encountering gem activation issues:
    102. Sven on 11 Oct 00:54:
      (that’ll teach me to hit return)…activation issues like this: rubygems.rb:246:in `activate’: can’t activate rails (= 1.2.4), already activated rails-1.2.4.7794] (Gem::Exception)I’ve tried with and without rails in the vendor directory, and I’ve tried messing with RAILS_GEM_VERSION in environment.rb to no avail.
    103. Alex Wayne on 12 Oct 21:55:
      Just beautiful. Praise be the breakpoint support again!
    104. Sebastian Holmqvist on 13 Oct 10:52:
      For all of us that have either been out of the bubble for a while or are completely new to some of the terminology used around here, an idea would be to define all official abbreviations on a single page and when using them in various contexts linking to that page.Other than that I can’t wait ‘til Rails 2.0 is final and burying myself under a ton of coding :)
    105. Bill Gates on 13 Oct 13:43:
      Wow. I’m gonna definitely try it out.
    106. Mike on 13 Oct 19:06:
      I’m having continuous problems while trying to install edge rails: Bulk updating Gem source index for: http://gems.rubyonrails.org Install required dependency activesupport? [Yn] ERROR: While executing gem … (Gem::GemNotFoundException) Could not find activesupport (= 1.4.3.7843) in the repository

      gem install rails --source http://gems.rubyonrails.org

      Any idea what’s wrong?

    107. Marc on 14 Oct 03:14:
      Mike -Delete your source_cache file. That usually fixes it. See:http://www.ruby-forum.com/topic/71069
    108. gissmoh on 14 Oct 07:22:
      Did not do the trick for me! I still get the same error:bullet:/tmp/rubygems-0.9.4 bullet$ sudo gem update Updating installed gems… Attempting remote update of activeresource Install required dependency activesupport? [Yn] ERROR: While executing gem … (Gem::GemNotFoundException) Could not find activesupport (= 1.4.3.7843) in any repository bullet:/tmp/rubygems-0.9.4 bullet$ sudo gem install rails—source http://gems.rubyonrails.org—include-dependencies ERROR: While executing gem … (Gem::GemNotFoundException) Could not find activesupport (= 1.4.3.7843) in any repository bullet:/tmp/rubygems-0.9.4 bullet$ sudo gem update Updating installed gems… Attempting remote update of activeresource Install required dependency activesupport? [Yn] ERROR: While executing gem … (Gem::GemNotFoundException) Could not find activesupport (= 1.4.3.7843) in any repository bullet:/tmp/rubygems-0.9.4 bullet$ sudo gem install rails—source http://gems.rubyonrails.org—include-dependencies ERROR: While executing gem … (Gem::GemNotFoundException) Could not find activesupport (= 1.4.3.7843) in any repository
    109. Piku on 14 Oct 10:52:
      I have the same problem as gissmoh and Mike: “Could not find activesupport (= 1.4.3.7843) in any repository”
    110. iGL on 14 Oct 11:58:
      The actual gem that gets installed via

      gem install activesupport—source http://gems.rubyonrails.org

      is 1.4.4.7843

      However, even after that, the installation of rails 2.0.0-pr fails.

      Therefore, there might be an error in the gem dependency specifications.

    111. J2o on 14 Oct 20:55:
      I’m praying that David will change his mind about releasing an updated Rails book for v2. In fact, I’m praying rather hard.
    112. Victor on 15 Oct 05:07:
      I looked further into the problem mentioned by gissmoh, piku, and iGl because I desperately needed rails 2 tonight (long story).My conclusion: the rails gem spec has the right build numbers, but the wrong minor version numbers for all dependencies.Workaround: 1) install all dependencies by hand with gem install dep-name —-source http://gems.rubyonrails.org 2) install rails with gem install rails -f—source http://gems.rubyonrails.org/ (so gems doesn’t complain about dependencies)the dependencies are: activesupport, activerecord, actionpack, actionmailer, and activeresource (this one is referenced correctly)Solution: update the gemspec please
    113. Victor on 15 Oct 05:14:
      I forgot to mention… for the workaround, you need to modify the gem specs in your local “gem” directory after you use the method I described above. You need to modify rails and activeresource.
    114. Sam Granieri on 15 Oct 05:23:
      Here’s the last word: Try this sudo gem install rails—source http://gems.rubyonrails.org -v 1.2.3.7707
    115. iGL on 15 Oct 12:34:
      Victor, Sam, Thank you.
    116. zeligf on 15 Oct 16:34:
      since activeresource depends on activesupport and the minor numbers don’t work. The only way now isgem install activesupport activerecord actionpack actionmailerthengem install -f activeresourcethengem intall -f rails
    117. Jeremy Kemper on 15 Oct 18:36:
      Sorry for the confusion, all! The 2.0 preview release gem versions + dependencies have been corrected. Please update.
    118. gissmoh on 15 Oct 18:50:
      Yäsli! Everything works again! Great! Thanx!!!!
    119. zeligf on 15 Oct 19:34:
      …and it works! thanks to jeremy & co time to get my hands dirty…
    120. Adam Jones on 16 Oct 11:15:
      gem install rails—source http://gems.rubyonrails.org installs rails 1.2.5 not the 2.o preview release?
    121. ed on 16 Oct 13:43:
      Adam, that’s what I got. (Maybe).
    122. thq on 17 Oct 02:31:
      J2o, Addison-Wesley will release The Rails Way in 20 Nov. If we see on toc, seem it covers Rails 2.0. It’s also very complete.
    123. Cristiano Betta on 17 Oct 13:20:
      I’m trying out 2.0 but need the autocomplete_for gem. simply running “gem install autocomplete_for” doesn’t seem to work, what would the proper command be?s
    124. Redmar Kerkhoff on 18 Oct 07:26:
      script/plugin install http://svn.rubyonrails.org/rails/plugins/auto_complete ?
    125. Cristiano Betta on 18 Oct 15:49:
      Tnx, just what I needed to know.
    126. Sven on 19 Oct 00:56:
      I was hoping the update would resolve the problem I posted above (messages 101 and 102), but no such luck. I installed the 1.2.5.7919 Rails gems, created a new project, installed acts_as_attachment, and ran rake test\plugins. The result was basically the same: “can’t activate rails (= 1.2.5), already activated rails-1.2.5.7919]”.So I tried gem cleanup rails, which left just the 1.2.5.7919 version, and repeated the steps above. This way it fails a little differently:

      `gem_original_require': no such file to load -- breakpoint (MissingSourceFile)
      
             from [...]/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'

      Can anyone offer any help resolving this?

    127. Jeremy Kemper on 19 Oct 01:06:
      All: please take any support issues to the mailing list or IRC so we can more effectively iron them out for the next release. Thanks!
    128. JALE on 21 Oct 09:16:
      Is there an anticipated date for a 2.0 AWDR book?
    129. Enterprise on 21 Oct 15:51:
      Fuck You DHH
    130. dusty on 22 Oct 15:40:
      I’d really love to see the benchmarks comparing 2.0 to merb and others. Are those available anywhere?
    131. streuth on 24 Oct 18:12:
      Are there any sample projects built with 2.0?
    132. meschach on 25 Oct 02:52:
      Fuck you Enterprise
    133. Jamal on 29 Oct 09:55:
      I still get the wrong version installed????

      sudo gem install rails—source http://gems.rubyonrails.org

      Password: Successfully installed rails-1.2.5.7919

      Please tell me what I’m doing wrong???

    134. Thomas on 29 Oct 17:30:
      Why isn’t autotest working with Rails as excepted I got too many errors throwing on the screen???
    135. Gaius on 29 Oct 20:59:
      I’m a bit confused on one thing with the mime_types and iPhone thing:How do I render the same template with two different layouts? For example, I’ve got a PostsController with a #new action, and layout = :site

      adjust_format_for_iphone changes the request, which means it wants both

      -a template in /app/views/posts/new.iphone.erb

      -a layout in /app/views/layouts/site.iphone.erb

      I really don’t want to have to copy my layout from /app/views/posts/new.html.erb to the iphone version; I just want the layout changed. (In some cases, I want both, but not always. For example, some pages need to have abbreviated content, not just a changed layout; other pages can have the normal content.)

      Suggestions? Some sort of render :template that includes the format?

    regards

    M.K.Jeevika


    Follow

    Get every new post delivered to your Inbox.