Some background:
I’m a jack-of-all trades, one of which is programming. I learned VB6 through Excel and PHP for creating websites and so far it’s worked out just fine for me. I’m not CS major or even mathematically inclined – logic is what interests me.
Current status:
I’m willing to learn new and more powerful languages; my first foray into such a route is learning Ruby. I went to the main Ruby website and did the interactive intro. (by the way, I’m currently getting redirected to google.com when I try the link…it’s happening to other websites as well…is my computer infected?)
I liked what I learned and wanted to get started using Ruby to create websites. I downloaded InstantRails and installed it; everything so far has been fine – the program starts up just fine, and I can test some Ruby code in the console. However my troubles begin when I try and view a web page with Ruby code present.
Lastly, my problem:
As in PHP, I can browse to the .php file directly and through using PHP tags and some simple ‘echo’ statements I can be on my way in making dynamic web pages. However with the InstantRails app working, accessing a .rb or .rhtml page doesn’t produce similar results. I made a simple text file named ‘test.rb’ and put basic HTML tags in there (html, head, body) and the Ruby tags <%= and %> with some ruby code inside. The web page actually shows the tags and the code – as if it’s all just plain HTML. I take it Ruby isn’t parsing the page before it is displayed to the user, but this is where my lack of understanding of the Ruby environment stops me short. Where do I go from here?
AMMENDMENT: This tutorial has helped me immensely! I’d suggest anyone who’s in my position go there.
First of all, you must disconnect the relationship between files and URLs.
Rails uses an MVC approach, which is worlds-different from scripts-based approach like ASP/PHP
In classic PHP, you have something like this
/usr/jake/example.com/htdocs//home.php, thanks!/home.phpis mapped to/usr/jake/example.com/htdocs/home.php/usr/jake/example.com/htdocs/home.php/home.phpshows “Hello World!”However, most MVC framework (Rails included) goes something like this:
routes.rb/home, thanks!/home, per the routing module, is handled with actionShowHomepage()in controllerFrontpageCtrFrontPageCtr.ShowHomepage()FrontPageCtr.ShowHomepage()prints “Hello World!”/homeshows “Hello World!”As you can see, there is no connection between what the user put into the addressbar and any script files
In a typical MVC framework, processing a request for any URL goes something like this:
routes.rb).rhtmlfile as actual HTML… there are, of course, other kinds of results e.g. send the user to another URL and whatnot.In short: You must disconnect the notion of scripts and URL first. When you’re building MVC websites, they are almost always NOT related in a way that most people understand.
With that in mind, you should be more comfortable learning Rails and MVC way of life.
I’m not a Rails pro so please correct me if I’m mistaken on any part.