SEO on Ruby on Rails  

25 Jun 2009
William Notowidagdo Kiranatama Staff
Knowledge

Here are some rails-way tips on SEO. Please share me your tips because there is always more than one way to do something when it comes to Ruby.

Continue reading...
William Notowidagdo Kiranatama Staff
Knowledge

Cucumber allow us to describe behavior in plain text. Because the text is written in a business-readable domain-specific language, beside serves as automated tests and development-aid, it also can be used as documentation. In this post we’re going to create a Rails application from scratch, and use Cucumber to define its behaviour.

Continue reading...
Administrator Kiranatama Staff
Knowledge

If you have the budget, choose Amazon EC2. And until Amazon EC2 provides a good web interface to manage the server instances (I heard they have a web interface now, but not sure if it's good), Rightscale might be a good choice. Rightscale has lots of documentation on setting up server instances for RoR, but I am quite sure this post will still help cut the time needed to finally launch your Rails app on Amazon EC2! First of all, follow the Rightscale instructions here for preliminary set up. Now, create the master & slave MySQL server instances. Follow the instructions here. One thing it seems to miss is the instruction to input DB_BINLOG_PREFIX with something like '/mnt/mysql-binlogs/mysql-bin'. Otherwise, the MySQL Master instance is in 'stranded' state as expected, only with a different reason. Click on Audit Entries on the instance, and it has to be stranded during 'DB Master Restore' Now to set up the Rails instances with load balancing, follow the instructions here. I like using Passenger, and it's a pity they dont have the template for that yet. But mongrel cluster will do just fine. Anyway, that instruction is not enough curiously. After tailing the mongrel error log, and googling, we found that we need to do something else for the HAProxy. Also if you need ImageMagick / rmagick / any other gems, you need to create a custom boot script, customize the Rails Frontend template and add the bootscript there. Another interesting thing is there is operational Rightscript that does db:migrate :) So we gotta create a custom Rightscript for that as well. Hope this helps!
Administrator Kiranatama Staff
Knowledge

Like Facebook Connect, Myspace Data Availability enables your site to take advantage of Myspace accounts. For example, you can have your users login to your site using their Myspace accounts, or list their Myspace friends on your own site. I didnt find an easy step-by-step tutorial even on a basic thing like getting the myspace user id of the logged in user in the external website; so I figure I'll write this post to help other Rails developers out there who are new to this. This is an example. First, in your rhtml, you'll want a link whereby if the user clicks on that, the user can login using his myspace account and then he can see his myspace user_id in your site (if you can get to this step, it's easy to add more complicated social features). <%= link_to 'See my myspace_user_id', {:action => 'see_my_myspaceuserid'} %> Now, how to implement 'see_my_myspaceuserid' ? You probably are looking at this tutorial here: http://developer.myspace.com/community/myspace/dataavailability.aspx Dont be daunted when you read over the 'Access Delegation' part. It's actually a basic Oauth authorization mechanism, and the Rails 'oauth' gem will help us a lot. Read about the gem here: http://oauth.rubyforge.org/ , or as usual, the best documentation usually are inside the code itself (in my Windows computer it's here: C:\ruby\lib\ruby\gems\1.8\gems\oauth-0.2.4\lib\oauth\consumer.rb). So here's how the controller looks like: def see_my_myspaceuserid @consumer = OAuth::Consumer.new('your OAuth Consumer Key', 'your OAuth Consumer Secret', {:site => 'http://api.myspace.com', :http_method => :get, :request_token_path => '/request_token', :authorize_path => '/authorize',:access_token_path=>'/access_token'}) @request_token = @consumer.get_request_token redirect_to @request_token.authorize_url + 'oauth_callback=display_myspace_user_id' end So once the user clicks on the link, he'll be redirected to myspace to login there. After he logs in there, he'll be redirected back to your site. Let's say the callback url is called 'display_myspace_user_id', so here's what it'll look like: def display_myspace_user_id # You can save the @request_token from action 'see_my_myspaceuserid' and use it here response = @request_token.get_access_token.get('/v1/user.xml') # Now use REXML::Document to parse response.body, and you'll get the user_id ! end How do I know that the parameter to access_token is '/v1/user.xml' ? Read here: http://developer.myspace.com/community/RestfulAPIs/resources.aspx That's it. You can use the access_token to do all sorts of REST API calls to Myspace now! I hope this helps.
Administrator Kiranatama Staff
Knowledge

If you have a Rails application that needs to include models from another Rails application, oftentimes you will want to add features to those methods, but you cannot since you cannot touch the other Rails app's codebase. If this is the case, you can use class_eval, which Neeraj explains nicely. For example, if you want to add an after_save to a class Example :
Example.class_eval do after_save :somemethod def somemethod end end
Note that you dont wanna put that code under vendor/plugins/ . Instead, put it under a place where it's executed everytime.