Use it with Rails and find out how to create your web applications
To fix this, create a file called index.rhtml and save it in the app\views\welcome directory. Files of this type are similar to PHP, ASP or JSP pages, in that they combine plain HTML with server-side script between special tags, as the following (rather contrived) example shows:
Everything between the <% … %> tags is Ruby code executed on the server. The expression <%= asks Rails to output what follows into the HTML.
Variables defined in the controller can also be used in the template. For example, you could insert the following line into the index method:
@title = ‘PCW Games Reviews’
and the following into the
section of the template:When you request the page, the value of the variable appears in the output. There is good reason not to put much code into templates. Rails makes it easy to put your code elsewhere; when you generate a Controller, the script creates a Helper module where you can put code for that set of pages.
Hooking up a database
To see the Rails magic, you need to hook up a database to the web
application.
By default, Rails uses the open-source MySQL, although there are drivers (called adapters) for several other database servers. On Windows I prefer SQL Server to MySQL, and it is free in the Express version.
Here’s how to use SQL Server 2005.
Both Ruby and Rails come out of the open-source community, and they are geared towards Unix-like operating systems in the same way ASP.Net is geared towards Windows.
Using SQL Server takes a bit of extra effort. First, you have to obtain the file ADO.rb by downloading the source of Ruby-DBI from rubyforge.org. Copy this file to /lib/ruby/site_ruby/1.8/DBD/ADO/ADO.rb, within your Ruby directory.
The next step is to create a database. We are making a site for games reviews, so open up SQL Server Management Studio or your preferred SQL Server tool, and create a database called PCW with a table called games.
The table must have an identity field called id, another example of convention over configuration. You can add other fields, such as game, platform, rating and comments. For convenience I set Allow Nulls to false for all the fields.
Related articles
Q.Why are some of the keys on my keyboard doing strange...
Q.Is my phone’s Bluetooth any use?
Q.Can I switch boot drives so that I can work on older...
St Helena, a 'small British village' in the mid-Atlantic, is seeking support and funding for a broadband connection
|
|
|
|
|
Computeractive Excel (2010) Online tutorialPrice: £19.99 |
Computeractive Word (2010) Online TutorialPrice: £19.99 |
Computeractive Powerpoint (2010) Online TutorialPrice: £19.99 |
Angry BirdsPrice: £9.99 |
Back Issue CD-Rom 14 (2011)Price: £15.99 |