Author Topic: Ruby on Rails  (Read 15278 times)

webwhy

  • Jackass IV
  • Posts: 608
  • Karma: +15/-10
Ruby on Rails
« on: June 21, 2005, 01:09:42 PM »
I've been messing with web programming languages for a couple of years now, and have settled on php as my utility/quick and dirty tool; however, anyone in the industry can't ignore the buzz about "rails".  I installed it on my gentoo box (linux isn't a requirement.  it will run on windows or OSX), and I have to say that so far I'm impressed.  It's still very young.  Version 0.11.1 is in gentoo's portage tree.  0.12.1 is the current version so it's actively devleoped.  Since the adoption of php5 has been anything buy enthusiastic,  I could see rails really taking a chunk out of php's market share, which i think is a good thing.  Ruby is a really slick language.  It' reminds me a lot of python, which is one of my passions, but it improves on python in a few areas.

The simpilicty of rails and the power of ruby make for an exciting product, and once it matures maybe some of us will free ourselves from the messy php landscape.

http://www.rubyonrails.org/

ober

  • Ashton Shagger
  • Ass Wipe
  • Posts: 14310
  • Karma: +73/-790
  • mini-ober is taking over
    • Windy Hill Web Solutions
Ruby on Rails
« Reply #1 on: June 21, 2005, 04:16:09 PM »
Do you have an example of some code?  What does it look like?  I haven't heard anything about it actually, and I'm not about to jump ship from PHP when it does what I need.

jverkoey

  • Jackass III
  • Posts: 226
  • Karma: +12/-2
    • http://TheJeffFiles.com/
Ruby on Rails
« Reply #2 on: June 21, 2005, 05:05:38 PM »
Yes I wouldn't mind seeing some code too...sounds interesting.
-Jeff Verkoeyen

webwhy

  • Jackass IV
  • Posts: 608
  • Karma: +15/-10
Ruby on Rails
« Reply #3 on: June 21, 2005, 08:21:58 PM »
I would like to show you something more complicated, but i'm just starting to learn it myself.  As a tester application, i'm rebuillding a simple time clock application I built for my office in php4.  I can show you a little code from that.

Rails uses a type of Model View Controller approach to coding web apps.  In rails the urls the browser requests are more or less mapped directly to methods defined in a controller class.  For example in my application I have a user table.  I create a user controller class with the following code.
Code: [Select]

class UserController < ApplicationController
    model :user
    scaffolding :user
end

These four lines of code do a lot of work for me.  The line mode :user ties this controller to the User model, and scaffolding :user provides a basic framework for creating, updating, listing, and deleting users.  I can already create or edit a record in the user table through the web with four lines of code.  I will admit that the interface is ugly, and will probably have to be modified in 9 out of 10 cases.

So i'm unhappy with the information shown by the list method in the UserController.  I can easily change it by "overriding" the list method in the UserController.  All the method has to do is load a data structure with the users in the database.  So the UserController looks like this now:
Code: [Select]

class UserController < ApplicationController
    model :user
    scaffolding :user

    def list
        @users = User.find_all
    end
end

So three more lines of code fill a list with all the user records in the table.  In ruby if you customize the behavior of the default scaffolding code, you need to provide a view for the new method.  Here's the view below:
Code: [Select]


 
    Timeclock users
 
 
   

Time Clock Users


   
     
     
     
     
      <% @users.each do |@user| %>
     
       
       
       
       
     
      <% end %>
   
ActionUsernameNameUser Type
<%= link_to("View", :action => "show", :id => @user.id) %><%= @user.user_name %><%= @user.first_name + ' ' + @user.last_name %><%= @user.user_type %>

 



This iterates over the instance variable @users and prints an edit link, user_name, name, and user type in an extremely simple html page.

So the url:  http://timeclock/user/list now points to my new "list template" just like http://timeclock/user/edit/1 points to the edit page for the user with id 1.

Still have a lot to learn, but so far it's been easy to pick up.  I like the fact that the control flow of the application is already done for you.  no more large switch statements or action variables.  

More later

ober

  • Ashton Shagger
  • Ass Wipe
  • Posts: 14310
  • Karma: +73/-790
  • mini-ober is taking over
    • Windy Hill Web Solutions
Ruby on Rails
« Reply #4 on: June 21, 2005, 09:41:09 PM »
<% and %> Sure does look a hell of a lot like ASP.  EWW.

Any mention whether the framework is multi-platform?  That's one thing I love about PHP... doesn't care whether it is running on *nix or Windows.

webwhy

  • Jackass IV
  • Posts: 608
  • Karma: +15/-10
Ruby on Rails
« Reply #5 on: June 21, 2005, 11:46:07 PM »
Yeah,  it mentions that the framework can be installed on mac, windows, and bsd's as well as linux.  

Don't get me wrong.  I'm a still a fan of php.  Just didn't want you to think i was trashing it... :)

ober

  • Ashton Shagger
  • Ass Wipe
  • Posts: 14310
  • Karma: +73/-790
  • mini-ober is taking over
    • Windy Hill Web Solutions
Ruby on Rails
« Reply #6 on: June 22, 2005, 12:52:40 PM »
What are the chances of any hosts actually running the platform tho?  I think the majority of us are stuck running PHP for the near future (at least those of us hosted on someone else's servers).

webwhy

  • Jackass IV
  • Posts: 608
  • Karma: +15/-10
Ruby on Rails
« Reply #7 on: June 22, 2005, 01:37:20 PM »
Can't argue with that.  Most large hosting shops will probably not support it until there is a great demand for it, which might be a while.  Though it wouldn't be difficult to do.  It can run in mod_fastcgi or through mod_ruby on apache.  I haven't been able to tell if there is any IIS support though.

It's still very young; I've just been seeing more and more written about it.

There are some hosts available.  They're listed on the rails website.

ober

  • Ashton Shagger
  • Ass Wipe
  • Posts: 14310
  • Karma: +73/-790
  • mini-ober is taking over
    • Windy Hill Web Solutions
Ruby on Rails
« Reply #8 on: June 22, 2005, 04:29:02 PM »
I try to avoid hosts that use IIS anyways ;)