PDA

View Full Version : Working with Ruby



lord_havoc
10-28-2007, 09:30 PM
I have recently been dabbling in Ruby and I've found I like it quite a bit but being the first actual language I've learned I don't know much about getting these files on the web. How would you run a ruby file in a web browser is basically what I'm asking. I know you can build blogs and photo galleries with it but I have no idea how that works.

thetestingsite
10-28-2007, 09:49 PM
You may want to check out a webhost with Ruby/Rails capabilites.

http://wiki.rubyonrails.org/rails/pages/RailsWebHosts

I am trying to get one of my servers to support it, but still running in the test phases right now.

Hope this helps.

lord_havoc
10-28-2007, 09:57 PM
Well my host does support it, but I don't have any clue of how to do anything of that magnitude. I probably should have mentioned I am absolutely new to Ruby. I downloaded it yesterday an played around and made a very simple program. Would you directly link to the .rb file? Or is there some sort of way to include the file within a PHP page? Also, are there any good tutorials on using databases with Ruby, I have never used a database before and I'm not getting the hang of those either.

Twey
10-28-2007, 10:01 PM
No, you need to use a framework such as Rails. You can run a Ruby file directly as a CGI script, but this is much less useful than using a framework. Ruby is not a Web-oriented language like PHP is, so you really need a framework to provide the necessary functions. You can make do with CGI, but it's ugly and much more difficult than using Rails, and you'll probably end up regretting it.

I suggest you become a lot more familiar with Ruby before you dive into interacting with a complex framework. The same goes for databases, probably, although databases are more-or-less the same no matter what language you use.

lord_havoc
10-28-2007, 10:10 PM
I tried to install Rails but it was not working for some reason. What can I do to get practice and get used to Ruby? I read a tutorial that walked through the basics of it but how could I take that knowledge to the next level, how would you make an actual program that does not run in the command prompt?

I hate to be such a nuisance, but again, I know absolutely nothing about programming.

Twey
10-28-2007, 10:35 PM
What makes you think that something with a text-based interface isn't an "actual program?"

lord_havoc
10-29-2007, 10:44 PM
Ah, true. Let me restate that, it came out wrong. How could I take that knowledge and apply it to making a program that runs with a GUI, (as I said, one that does not run in the command prompt) such as a photo viewer, blog, or game.

BLiZZaRD
10-30-2007, 02:35 PM
The first thing you need to do is figure out what you want to do. What type of program do you want to make?

Then use what you already know and start coding. After that find solutions to the errors you get, one by one. Making mistakes in coding is what helps you learn the language.

To install rails on your computer you can follow this pretty simple tutorial (http://www.hostmysite.com/support/rubyonrails/localinstall/)

Then you just need guidance:

http://rubylearning.com/

http://poignantguide.net/ruby/

http://learnruby.com/

There is a PDF file "the ruby bible" or something like that which I will find and post here as well, it is rather good reading.

<EDIT>
Found the book, and a quick refernce guide...

the book (http://www.infoq.com/minibooks/ruby/)

The cheat sheet (http://www.zenspider.com/Languages/Ruby/QuickRef.html)

</EDIT>

Twey
10-30-2007, 03:45 PM
How could I take that knowledge and apply it to making a program that runs with a GUI, (as I said, one that does not run in the command prompt) such as a photo viewer, blog, or game.You need a GUI toolkit (http://www.trug.ca/Ruby_GUI_Toolkits) and Ruby bindings for it. I suggest FOX and FXRuby for applications that must be very lightweight (fast to run/small program size), and Ruby/Qt otherwise, since Qt has a huge selection of widgets.

lord_havoc
10-30-2007, 10:37 PM
Here's another question. Explain what a framework is exactly? What's different about writing ruby code with and without rails? What exactly does rails allow me to do that I couldn't before it was installed?

Okay, so that was actually three, but I just wanted to be clear and get the answer I'm looking for.

Twey
10-31-2007, 12:00 AM
A framework is an "blank slate" application to which you provide code to do as you like. In this case, Rails is an application that interfaces with your web server and runs your scripts when appropriate (e.g. when the user's request matches an URL you'd decided should point to a certain function; I'm not entirely sure how Ruby does it, but it'll be something like that). It also provides various classes and functions to help you write HTTP-based applications more easily.

Without a Web framework such as Rails, you'd probably be using CGI. CGI provides data to your script in a very rough form, and takes output in an equally low-level manner: about half your application would likely involve handling all this low-level stuff and translating it into a higher-level form.

lord_havoc
10-31-2007, 12:03 AM
So Rails makes it easier for a web server to understand the language? Does this change any coding? Do I use different syntax, methods, things like that or is is still the same?

Twey
10-31-2007, 12:22 AM
No, it doesn't change the language itself. It's sort of like working with a library.

lord_havoc
10-31-2007, 12:36 AM
Oh thats cool! Where can you find all the things it adds?

Twey
10-31-2007, 12:50 AM
Start with: http://wiki.rubyonrails.org/rails/pages/Tutorial

lord_havoc
10-31-2007, 01:19 AM
Okay, I got everything up and running and I'm following a tutorial on making a photo gallery. There is an .rhtml that calls for the stylesheet in, what I beleive to be , AJAX. The codeing for the page is



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Flickr</title>
<%= javascript_include_tag :defaults %>
<%= stylesheet_link_tag 'flickr' %>
</head>

<body>
<%= yield %>
</body>
</html>


For some reason it doesn't see the style sheet and therefore doesn't display styles I have made. As far as I can see, I typed exactly what he did but I must be missing something.

Twey
10-31-2007, 07:30 AM
What's the rest of the code?

lord_havoc
10-31-2007, 08:39 PM
That file was application.rhtml

index.rhtml is:



<%= form_remote_tag :url => {:action => 'search'}, :update => 'photos' %>

<fieldset>
<label for="tags">Tags</label>
<%= text_field_tag 'tags' %>
<%= submit_tag 'Find'%>
</fieldset>

<div id="photos"></div>

<%= end_form_tag %>


And flickr.css is


body{
background-color: #888888;
font-family: "Trebuchet MS";
font-size: .8em;
margin: 25px;
}

form{
margin: 0px;
margin-bottom: 10px;
background-color: #eeeeee;
border: 5px solid #333333;
padding: 25px;
}

fieldset{
border: none;
}

Twey
11-01-2007, 09:13 AM
It's called 'flickr.css' isn't it? stylesheet_link_tag won't add the extension on for you.

lord_havoc
11-01-2007, 09:18 PM
Well I didn't think so, but I'm new to AJAX. And the guy in the video didn't use the extension. I thought maybe that piece of code new to look for css files.

Either way, it still doesn't work. :confused:

Twey
11-01-2007, 09:24 PM
Well, since I don't really know either Ruby or Rails, this is about as far as I go. If you want more help you'll probably have to ask in the IRC channel or a more appropriate forum.

lord_havoc
11-01-2007, 09:27 PM
Okay, but thank you so much for your help!