`
Gene
  • 浏览: 51424 次
社区版块
存档分类
最新评论

Installing Ruby on Rails with Lighttpd and MySQL on Fedora C

    博客分类:
  • Ruby
阅读更多
Following article is copied from http://digitalmediaminute.com/howto/fc4rails/#installLighttpd

引用
Introduction
This how-to is aimed at getting you started with Ruby on Rails installed on the Fedora Core 4 Linux distribution using the Lighttpd web server and mySQL database server.

Why use this combination of Fedora Core 4 (FC4) and Lighttpd? Well, lets start with FC4. Fedora aims to be a complete, general-purpose open source operating system that is designed to be easily installed and configured with a simple graphical installer. Packages and their dependencies can be easily downloaded and installed with the yum utility. FC is updated regularly with new releases of Fedora come out every six months.

Fedora was born from the original Red Hat Linux distribution and aims to be a conventional Linux home users will use. This makes it a perfect platform to setup up our Rails server.

I chose Lighttpd as it natively supports two core features that rails requires out of a web server - Fastcgi and URL rewriting. FastCGI is removes a lot of the limitations of CGI programs. CGI programs have the problem that they have to be restarted by the webserver for every request which leads to really bad performance values. FastCGI removes this limitation by keeping the process running and handling the requests by this always running process.

Lurking in the Ruby on Rails Wiki, many Rails experts seem to feel that Lighttpd is the best server platform for running Rails.

You may be wondering why you might want to install Ruby on Rails with FC4 when you could just as easily install it on your Windows or Mac box. Well, when experimenting with new development frameworks (such as Rails) I tend to avoid installing such software on my production systems. The last thing I need is to bring my everyday systems down due a bad software install or system conflict. So I try to install experimental technologies on separate, old, spare systems. And Linux makes alot of sense as the OS is free.

Disclaimers
Before you begin this how-to, I feel it is important to be aware that I am by no means a Linux expert. Although I have used Linux to run Apache and Mail servers for my personal use, I do not use Linux in a professional environment. So the information provide here is simply provided by that of a web developer who enjoys hacking around in Linux. Having said that, I have installed this mix of OS and applications over 10 times while preparing this how-to, so I am sure that you will have no problems if you follow along.

If you're new to Linux, you should follow this how-to by installing the OS on an old system. If you have some experience, you can install FC4 so that it co-exists with your Windows OS - but make sure you know what you're doing before you try this!

Let's get started!

Getting Fedora Core 4
You can obtain Fedora Core 4 from the Fedora website. Visit their downloads page and grab the distribution that matches your platform (i386 is for Intel based systems, x86_64 is for 64-bit processors, and ppc is for Mac based computers). If you have a DVD-ROM drive that you can boot from, I would recommend downloading the DVD ISO image as you won't have to swap discs during the installation process. If you have a bittorrent client, you might also want to download FC4 using a torrent. This is from my experience the fastest way to download FC4.

Once you have downloaded the appropriate ISO disc image, you can burn it using your favorite CD burning software like Nero.

Installing Fedora Core 4
This section is intended to be a brief summary of installing FC4 and should be enough to get you going. If you're interested in finding out more about installing FC4, you can view a very detailed installation document at the Fedora website.

Installing FC4 is a very straight forward process. In fact, I think it may even install easier than Windows. FC4's driver support is excellent, and the installer walks you through the installation process in just a few simple steps. So let's get started! Place your FC4 CD or DVD into your optical drive and startup your computer (Note: you will have to configure your system BIOS to boot from your optical drive). Turn on your computer and wait for the installer to begin. The first prompt you will get will ask you if you want to examine your installation media. This is a good idea, as it will confirm that your download worked. Once the installation media has been tested, you will taken to FC4's GUI based installation.

First you'll be asked to choose your language and keyboard. Choose the one that best suits your needs. Next, you will be asked to Install Fedora Core or Upgrade an Existing Installation. Choose to Install Fedora Core. On the next screen, you will be asked to choose an installation type. You want to choose Custom. A key security strategy while using Linux as a server, is to install only the services that you need. Choosing Custom here, will let us pick only what we need.

The next screen asks you how FC4 should parition your hard-drive. I am assuming that you are installing this on a computer that currently has no other operating system. If this is the case, choose Automatically Partition. If you would like to dual-boot with another OS, you should stop here and do some research on dual-booting Linux with another OS. This is beyond the scope of this how-to. On the next three screens, accept the defaults.

Next you can configure your Network Devices. Enter you TCP/IP settings much like you would in Windows (ie. DHCP, Gateway, DNS. On the next screen you will be asked to enable the built-in firewall. At this point, you should choose to Enable Firewall and allow access to the SSH and HTTP services.

Next, you will be asked to type in a Root Password. The root account is available on all *nix based operating systems and is used to help you administer your OS. Normal users, cannot perform many administration tasks unless they temporarily give themselves root access permissions. By setting the root password, you will be able to provide yourself with this privelege. So type in a password that you will not forget, but at the same time is secure (at least eight characters, at least one character being a numeric and one character being uppercase).

Next you will need to choose which packages should be installed. You can keep all the defaults with the exception of the following:

Remove the checkboxes next to:
Office/Productivity
Sound and Video
Graphics
Printing Support
Add checkboxes next to:
Development Tools
Now click the Next button. Click Next again to begin installing the FC4. Once the packages have been installed, you will be prompted to reboot your system. Choose to reboot, and FC4 will start up for the first time at which point you will be walked through a wizard where you will setup the date and time, choose a display and other tasks.

The most notable setting here, is to enter a system user. Choose a username for your own login account then enter a username and password and click next then continue to click next until you are prompted to Finish the installation.

That was it! If all went well, the entire installation process should have taken about 20 minutes! Try that with Windows!

Now we need to login for the first time. Before you enter your username and password though, let's choose a session type. Near the bottom of the login screen, you will see a button titled Session. Click this button and from the list of options that appear, select GNome. Now type in your username and press enter, then type in your password and press enter.

Linux Administration
To perform many Linux administration tasks, you need to be logged in as the root account. But in Linux, it is a bad idea to login as the root user. Instead, we log in as a regular user, then switch to a root user only when needed via the terminal. To give us this administrative power, we prefix many of our terminal commands with the sudo command. Sudo (superuser do) allows a system administrator to give certain users (or groups of users) the ability to run some (or all) commands as root or another user while logging the commands and arguments.

Initially we have a problem using the sudo command, as the system user is not a member of the sudoers list. To fix this, we need to edit a file named sudoers.

But, there is a hiccup here, because to edit the sudoers list, we must be logged in as the root user - which if you remember is a bad idea in Linux. So what we will do here, is open a terminal window and create a root terminal session. This make terminal think that we are logged in as root.

Lets start by opening a new terminal window. Click on the Applications menu located at the top-left of your desktop, then choose the System Tools submenu then choose Terminal. Now lets create the root terminal session by using the su command which allows us to temporarily switch to the root user. So from the terminal window that you just opened, type:

su

then press enter. You will be asked to type into your password at which point you will type in the Root password you supplied when you installed FC4. Once you password has been accepted, you will now be typing and running command in the terminal as the root user!

Now lets edit the sudoers file by typing the following command into the terminal:

gedit /etc/sudoers

A graphical editor should now appear with the sudoers file open. Scroll down the file until you see a line that reads:

# User privilege specification
root          ALL=(ALL)      ALL

and copy and paste it immediately below that line. Then change the word root to the same username as you chose for you system user. Your User privelege specification should now look like this:

# User privilege specification
root          ALL=(ALL)      ALL
yourUserName  ALL=(ALL)      ALL

Click te Save icon on the toolbar, then close the editor window.

Finally we will end our root terminal session by typing the following command into our terminal window:

exit

YUM
What is Yum?
YUM, or Yellow Dog Updater Modified, is a program that allows users to easily update, add or remove packages on their Linux systems. YUM provides a command-line interface to managing the packages that are available as RPM (Red Hat Package Manager) files. YUM communicates with repositories that contain a database of rpms and headers. The rpms contain the actual program and data that you would like to install and the headers contain information about the dependancies that are required by the program you are attempting to install. So if you want to install program x, you simply type yum install x and YUM will download and install program x as well as any other programs that are required by program x.

Looking for a more permanent Rails hosting solution?
Dreamhost offers great Rails hosting packages. Signup now and enter the promotion code dmmrails to recieve $70 of your first year of hosting. Your total cost for one year will be $49 - that's only about $4 per month!
Signup Now!
Installing Yum Extened GUI
The Yum program is commonly run from a terminal window, but if you're like me, you may prefer to use programs that have graphical user interface(GUI). Throughout this how-to we are going to attempt to use GUI's whereever possible and we'll try to keep our time using the command-line terminal to a mimimum. The first program we are going to install is Yum Extender which is a program that allows you to install, update and remove packages from GUI. It makes viewing and managing Fedora packages very easy.

To get Yum Extender, we are going to use the YUM command-line program. If your terminal window is not open, open it now. When we use YUM, we must be a root user, so we will make sure we use the sudo command to temporarily give us that access. So we can install Yum Exender by typing:

sudo yum install yumex

You will now be asked to enter your password by the sudo program. Type in the password you used for your system account and press enter.

As this is the first time you have run YUM, it will spend a bit of time downloading and initializing the YUM repositories, then you will finally be prompted whether or not you want to install Yumex. Select yes, and yumex will be installed. Now lets close the terminal window.

Upating Fedora Core 4
Now lets update our FC4 installation using Yum Extender. Keeping your FC4 installation up to date is very easy and an important task that you should run as often as possible. This will help keep your FC4 linux as secure and bug-free as possible. Updates to FC4 software happen on almost a daily basis!

We begin by running Yum Extender by clicking on the Applications menu, then choosing System Tools then choosing Yum Extender. It's worth noting that Yum Extender needs to be run by the root user, so when you start Yum Extender, you will be asked for your root password. Type the password in when prompted and then click the OK button.

A nice simple GUI appears and the program will once again update the YUM repositiores and check to see which existing packages need to be updated. Once Yum Extender has finished updating its package list from the repositories, you will see a list of all installed packages on your system that need to be updated. Click the Select All button at the bottom of the Yum Extender window, then click the Update button. Follow the prompts and wait for the updates to download and install, then we will move on to the next step. Note do not close Yum Extender as we will continue to use it for the next few steps.

Installing Ruby on Rails
Our next step is to begin installing Ruby on Rails. This is a three step process that requires us to install the Ruby programming language, followed by Ruby Gems (much like YUM but for Ruby extensions) then finally Rails. Please note that if you've installed Rails before, DO NOT install the RubyFCGI Gem as it causes problems on FC4 and Lighttpd.

Installing Ruby
To install Ruby, while still in YUM Extender, click on the Install icon that is located on the left toolbar. Now we can search for uninstalled Ruby packages by typing Ruby into the filter textbox near the top of the Yum Extender window then pressing the Enter key on your keyboard. Now you should see a list of all Ruby related software that can be installed on your FC4 system. The packages that we need and the ones that you place check marks next to are:

ruby
ruby-devel
ruby-libs
irb
rdoc
Once you have selected these packages, click the Install button at the bottom of the Yum Extender window, follow the prompts and wait for the packages to download and install, then we will move on to the next step.

Installing Ruby Gems
To install Ruby Gems, we'll need to go back to a Terminal window and type the following commands (pressing enter at the end of each line):

wget http://rubyforge.org/frs/download.php/5207/rubygems-0.8.11.tgz
tar zxvf rubygems-0.8.11.tgz
cd rubygems-0.8.11
sudo ruby setup.rb

If all goes well, you should see a message that says Successfully build Ruby Gems.

Now lets cleanup the files we downloaded and extracted by typing:

cd ..
rm ruby* -drf  

Installing Rails
Once Ruby Gems has installed, installing Rails becomes very easy. From the same terminal window type:

sudo gem install rails --include-dependencies

Wait for the Rails software to download and install, then close the terminal window.

Installing Lighttpd
To install lighttpd, we will return to YUM Extender. Make sure you are on the Install screen, and in the Filter textbox, type lighttpd. Now select the following packages:

lighttpd
lighttpd-fastcgi
Once you have selected these packages, click the Install button at the bottom of the Yum Extender window, follow the prompts and wait for the packages to download and install, then we will move on to the next step.

Installing mySQL
To install mySQL, we will stay in YUM Extender. Once again, make sure you are on the Install screen, and in the Filter textbox, type mysql. Now select the following packages:

mysql
mysql-server
mysql-devel
mysql-administrator
Once you have selected these packages, click the Install button at the bottom of the Yum Extender window, follow the prompts and wait for the packages to download and install, then we will move on to the next step.

Configuring mySQL
Next we need to make a small configuration tweak to mySQL. It appears as though there is a problem between Rails (or the Ruby mySQL bindings) that makes the password storage method in mySQL 4.1 incompatible. To fix this we will edit the file /etc/my.cnf. Open a terminal window and type:

sudo gedit /etc/my.cnf

Now change the line that reads:

old_password=1

to:

old_password=0

Click te Save icon on the toolbar, then close the editor window.

Installing FastCGI Development Libraries
Now we need to install the FastCGI Development Libraries. These are required by Ruby-Fastcgi Bindings that will be installed in the next step. To install the FastCGI Development Libraries, we'll need to go back to a Terminal window and type the following commands (pressing enter at the end of each line):

wget http://www.fastcgi.com/dist/fcgi.tar.gz
tar zxvf fcgi-2.4.0.tar.gz
cd fcgi-2.4.0
./configure
make
sudo make install

Wait for the compilation to finish, then cleanup the files we downloaded and extracted by typing:

cd ..
rm fcgi* -drf  

Now close the terminal window.

Installing Ruby FastCGI Bindings
Now we need to install the Ruby-Fastcgi Bindings. To install the Ruby-Fastcgi Bindings, we'll need to go back to a Terminal window and type the following commands (pressing enter at the end of each line):

wget http://sugi.nemui.org/pub/ruby/fcgi/ruby-fcgi-0.8.6.tar.gz
tar zxvf ruby-fcgi-0.8.6.tar.gz
cd ruby-fcgi-0.8.6
ruby install.rb config
ruby install.rb setup
sudo ruby install.rb install

If all goes well, you should see a message that says install done, then cleanup the files we downloaded and extracted by typing:

cd ..
rm ruby-fcgi* -drf 

Now close the terminal window.

And that concludes the installation of software required to get our server up and running!

Starting the lighttpd and mySQL Daemeons (services)
Now that all our software is installed, let run our servers and configure them to start with each reboot or restart of our FC4 system. To do this, we need to click on the Desktop menu located across the top of your FC4 desktop. Next choose System Settings, then choose Server Settings, ten choose Services. You will be asked for your root password, so type it in then click OK.

Now you should see the Service Configuration window. Along the left pane, you will see a list of all programs that can be started as or are currently running as a service. Scroll down the list until you see lighttpd. Place a checkmark next to it then click on the Start toolbar button. You should see a message that says lighttpd start succesful.

Now lets do the same for mySQL. Scroll down the list until you see mysql. Place a checkmark next to it then click on the Start toolbar button. You should see a message that says mysql start succesful.

Now both the lighttpd and mysql servers have been started, but we also want them to start automatically each time we start FC4. This is accomplished by clicking on the Save button in the toolbar!

Testing Lighttpd
Our next step is to make sure that Lighttpd is running. To test this, simply open the Firefox web browser by clicking on the Applications menu, choosing Internet then clicking on Firefox Web Browser.

Once Firefox opens, type http://localhost into the address bar then click enter. If the server is running you will see a webpage that says lighttpd - Lightning fast, light system requirements.

Securing mySQL
The first step to securing your mysql server is to set a root password. By default, when you install mysql, a root user account is created with a blank password. This is obviously a huge security hole and should be fixed immediately. To set a new password for the root account, open a new terminal window and start the mySQL client by typing:

mysql -u root -p

You will be prompted for a password, and as the password is currently empty, simply press the enter key.

Now lets change the password by typing the following command and replacing newPassword with a new password of your choice:

SET PASSWORD FOR root@localhost=PASSWORD('newPassword');

You will be prompted to enter a password. This password it is asking for is your old password, which by default is blank, so simply press enter and your new password will be applied to your account. Next, exit the mySQL client by typing:

exit

Now let's test you new password by logging into your mysql client by typing into a terminal window:

mysql -u root -p

You will be prompted for a password, type in your new password. You should now be logged into your mysql server.

Now lets delete some user account that have no username and/or no passwords. These are insecure accounts and should be deleted. In the same terminal window, type the following commands:

use mysql;
delete from user where user='';
delete from user where host='localhost.localdomain';

Now type exit to leave the mysql program.

Your mysql server is now as secure as your password.



Looking for a more permanent Rails hosting solution?
Dreamhost offers great Rails hosting packages. Signup now and enter the promotion code dmmrails to recieve $70 of your first year of hosting. Your total cost for one year will be $49 - that's only about $4 per month!
Signup Now!
Install Miscellaneous Software
The next step is to install 3 pieces of software that will help with you Linux development experience. The three items to install listed below will not be used in this how-to, but when you begin to develop your first Rails application, these tools will be very useful.

Bluefish Web Development Environment
There are a few Web Development packages available for Linux. For example you may have noticed that Eclipse is available as an option when you install FC4. Although Eclipse is an excellent development environment for Java and Web Application projects, it is really a big and complex program and probably more than we need for this tutorial. If you are familiar with Eclipse, please by all means go ahead and install it, but for this tutorial I am going to use the BlueFish HTML Editor. It is a capable but simple editor, but the main thing that drew me to it is the fact that it supports Ruby syntax highlighting! So lets install it.

To install BlueFish, we will need to start YUM Extender. Once again, make sure you are on the Install screen, and in the Filter textbox, type bluefish. Now select the following package:

Bluefish
Once you have selected this package, click the Install button at the bottom of the Yum Extender window, follow the prompts and wait for the package to download and install, then we will move on to the next step.

MySQL Query Browser
The MySQL Query Browser is the official GUI developed by the fine people who brought you the popular MySQL family of database products. MySQL Query Browser is an awesome piece of software that will allow you to manage your databases and tables through a very complete GUI. MySQL Query Browser is available for Windows, Mac OSX and Linux. We will of course, install the Linux version.

Start by opening a new terminal window and type the following command.

wget http://mysql.mirror.cygnal.ca/Downloads/MySQLAdministrationSuite/mysql-query-browser-1.1.12-linux.tar.gz

Next, we install the program by untaring the downloaded file by typing:

tar zxvf mysql-query-browser-1.1.12-linux.tar.gz

This is not really an installation but rather a simple extraction of the MySQL Query Browser files. What we need to do now is to create Launcher item to this program. You can start by closing all open windows, then right mouse click on your Linux desktop. A popup menu will appear and you will need to click on the item that says Create Launcher. The Create Launcher dialog box will appear. In the Name field, enter MySQL Query Browser. Next to the Command drop down list, click on the Browse... button. A Browse dialog will open where you should by default be placed in your home folder (if not, click the Home button at the top of the dialog). Look for a folder named mysql-query-browser and double-click on it to open. Now double click on the folder named bin. Next click on the file mysql-query-browser then click the Open button. Next you need to choose an icon for the Launcher item. Click on the square shaped button that says No Icon and choose an icon, then click the OK button.

Microsoft True Type Fonts
Fedora Core and other Linux distributions come without Microsoft True Type Fonts such as Arial, Verdana, Tahoma and Times New Roman. As these fonts are used by most web developers, you'll probably want to install these on your FC4 installation. You can follow the instructions provided by Mauriat Miranda in his guide - Install Microsoft True Type Web Fonts. I would write the instructions here, but Mauriat has provide a simple RPM package that includes the fonts and system settings.

Configuring Lighttpd
Alright, were done installing software, so lets begin to test our first Rails application. The goal here is to create a very simple Rails application to make sure everything with our installation is correct. Our first step is to modify our lighttpd configuration file, but before we do, lets backup the one that came with our installation (you may want to look at this one later, as it is much more complete than the one provided here). To backup the old configuration file we're going to move it to a new file, so open a terminal window and type:

cd /etc/lighttpd
sudo mv lighttpd.conf lighttpd.conf.old


Now we'll create new lighttpd configuration file by typing:

sudo gedit lighttpd.conf

An empty GEdit window will appear. Copy the text below into this new editor window and change every instance of yourHomeDir to your system user name. Click the save button and close GEdit.

server.port = 80
server.pid-file = "/tmp/test_lighttpd.pid"

server.modules = ( "mod_redirect", "mod_access", "mod_fastcgi", "mod_accesslog", "mod_simple_vhost" )

server.document-root = "/srv/www/lighttpd/"
server.indexfiles = ( "index.php", "index.html" )
accesslog.filename = "/var/log/lighttpd/access_log"
server.errorlog = "/var/log/lighttpd/error_log"

# simple virtual hosting
simple-vhost.server-root = "/home/yourHomeDir/"
simple-vhost.default-host = "test"
simple-vhost.document-root = "public"

# Start of test vhost
$HTTP["host"] == "test" {
  server.document-root = "/home/yourHomeDir/test/public/"
  accesslog.filename = "/home/yourHomeDir/test/log/access.log"
  server.indexfiles = ( "dispatch.fcgi", "index.html" )
  server.error-handler-404 = "/dispatch.fcgi"

  # rails stuff
  #### fastcgi module
  fastcgi.server = (
    ".fcgi" => (
      "test" => (
        "socket" => "/tmp/test1.socket",
        "bin-path" => "/home/yourHomeDir/test/public/dispatch.fcgi",
        "min-procs" => 1,
        "max_procs" => 2
      )
    )
  )
}
# End of test vhost

# mimetype mapping
mimetype.assign = (
".rpm" => "application/x-rpm",
".pdf" => "application/pdf",
".sig" => "application/pgp-signature",
".spl" => "application/futuresplash",
".class" => "application/octet-stream",
".ps" => "application/postscript",
".torrent" => "application/x-bittorrent",
".dvi" => "application/x-dvi",
".gz" => "application/x-gzip",
".pac" => "application/x-ns-proxy-autoconfig",
".swf" => "application/x-shockwave-flash",
".tar.gz" => "application/x-tgz",
".tgz" => "application/x-tgz",
".tar" => "application/x-tar",
".zip" => "application/zip",
".mp3" => "audio/mpeg",
".m3u" => "audio/x-mpegurl",
".wma" => "audio/x-ms-wma",
".wax" => "audio/x-ms-wax",
".ogg" => "audio/x-wav",
".wav" => "audio/x-wav",
".gif" => "image/gif",
".jpg" => "image/jpeg",
".jpeg" => "image/jpeg",
".png" => "image/png",
".xbm" => "image/x-xbitmap",
".xpm" => "image/x-xpixmap",
".xwd" => "image/x-xwindowdump",
".css" => "text/css",
".html" => "text/html",
".htm" => "text/html",
".js" => "text/javascript",
".asc" => "text/plain",
".c" => "text/plain",
".conf" => "text/plain",
".text" => "text/plain",
".txt" => "text/plain",
".dtd" => "text/xml",
".xml" => "text/xml",
".mpeg" => "video/mpeg",
".mpg" => "video/mpeg",
".mov" => "video/quicktime",
".qt" => "video/quicktime",
".avi" => "video/x-msvideo",
".asf" => "video/x-ms-asf",
".asx" => "video/x-ms-asf",
".wmv" => "video/x-ms-wmv",
".bz2" => "application/x-bzip",
".tbz" => "application/x-bzip-compressed-tar",
".tar.bz2" => "application/x-bzip-compressed-tar"
)


Once again, make sure you change every instance of yourHomeDir to your system username.

What we've done here is to configure lighttpd to use virtual hosts. Virutal host uses the Simple Virtual Host module as defined in the server.modules section. The advantage of using virtual hosts, is that we can simply add addional vhost sections to our lighttpd.conf file to run different Rails applications. For more information on virtual hosts and lighttpd, see the lighttpd documentation website.

The host name we have configured lighttpd to use is test, but before we can access that host, we need to add an entry to our hosts file. The hosts file, is a simple text file that Linux checks before it does and Domain Name Lookup. If it finds the host in this file, it resolves it to the IP address specified for that host. So lets edit the hosts file by opeing a terminal window and typing:

sudo gedit /etc/hosts

Then add the following line to the end of the file:

127.0.0.1     test

Save the file and close the GEdit window.

Finally lets restart our lighttpd server so that our changes to the configuration file are reloaded. To do this, we need to click on the Desktop menu located across the top of your FC4 desktop. Next choose System Settings, then choose Server Settings, ten choose Services. You will be asked for your root password, so type it in then click OK. Now click on the service named lighttpd and then click on the Restart toolbar button. Check to make sure that the server starts properly, and if not, double check the accuracy of the lighttpd.conf file.

Creating a Test Rails Application
To create our test Rails application, we need to perform the following tasks:

Create our database
Create the Rails application
Edit the Rails/database configuration file
Generate a controller for our table
Generate the scaffolding of our application
If you're not familiar with Rails, the terms model and scaffold probably don't mean much to you, but don't worry, follow along with the next few steps then be sure to read the articles that I link to at the end of this how-to. They will orient you with the lay of the land when it comes to Rails development.

Lets start by creating the database. Open a terminal window and login to our MySQL client by typing:

mysql -u root -p

You will be prompted for a password, type in your password and press enter. You should now be logged into your mysql server. Now type the following commands into the MySQL client:

CREATE DATABASE contacts;
USE contacts;

CREATE TABLE contacts (
id int(10) unsigned NOT NULL auto_increment,
name varchar(50) NOT NULL default '',
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

INSERT INTO contacts VALUES (1,'Jim Rutherford');
INSERT INTO contacts VALUES (2,'Robert Blawbla');

exit

Next we're going to Create the Rails application, but before we issue the rails command, we need to make sure we're in our home directory so in your teminal window type:

cd /home/yourUserName

substituting yourUserName with your system user name. Next create your Rails application by typing:

rails test

Next we need to set file permissions on the rails log and public folder

cd test
sudo chmod -R 775 log
sudo chmod -R 775 public

Using the BlueFish web editor, we are going to edit the database.yml file that is located in /home/yourUsername/test/config folder. To start Bluefish, click on the Applications menu then choose Programming then click on the Bluefish item. Using the file navigation pane on the left side of the window, navigate to the /home/yourUsername/test/config folder then open the database.yml file by double-clicking on it. Now change the development section so that is reads:

development:
  adapter: mysql
  socket: /var/lib/mysql/mysql.sock
  database: contacts
  host: localhost
  username: root
  password: yourPassword

Now save the file and close it.

Next, open a new terminal window and type:

cd test

Now lets generate the model for our contacts table by typing:

script/generate model contact

Finally, we'll create the scaffold by typing:

script/generate scaffold contact

Scaffolding is really cool - in very brief terms, it creates listing, editing, deleting, and adding forms for your web application!

So now for the grand finale! Let's open our Firefox web browser and test our test application. In the Firefox location bar, type http://test/contacts. If all goes well, you will see a screen that lists the two names in our database along with some action links for editing, adding and deleting records.
分享到:
评论

相关推荐

    离散数学课后题答案+sdut往年试卷+复习提纲资料

    离散数学课后题答案+sdut往年试卷+复习提纲资料

    智能点阵笔项目源代码全套技术资料.zip

    智能点阵笔项目源代码全套技术资料.zip

    英文字母手语图像分类数据集【已标注,约26,000张数据】

    英文字母手语图像分类数据集【已标注,约26,000张数据】 分类个数【28】:a、b、c等【具体查看json文件】 划分了训练集、测试集。存放各自的同一类数据图片。如果想可视化数据集,可以运行资源中的show脚本。 CNN分类网络改进:https://blog.csdn.net/qq_44886601/category_12858320.html 【更多图像分类、图像分割(医学)、目标检测(yolo)的项目以及相应网络的改进,可以参考本人主页:https://blog.csdn.net/qq_44886601/category_12803200.html】

    (31687028)PID控制器matlab仿真.zip

    标题中的“PID控制器matlab仿真.zip”指的是一个包含PID控制器在MATLAB环境下进行仿真的资源包。PID(比例-积分-微分)控制器是一种广泛应用的自动控制算法,它通过结合当前误差、过去误差的积分和误差变化率的微分来调整系统输出,以达到期望的控制效果。MATLAB是一款强大的数学计算软件,而Simulink是MATLAB的一个扩展模块,专门用于建模和仿真复杂的动态系统。 描述中提到,“PID控制器——MATLAB/Simulink仿真以及性能比较与分析”表明这个资源包不仅提供了PID控制器的模型,还可能包括对不同参数配置下的性能比较和分析。博主分享的是“最新升级版框架的Simulink文件”,意味着这些文件基于最新的MATLAB版本进行了优化,确保了与不同版本的MATLAB(从2015a到2020a共11个版本)的兼容性,这为用户提供了广泛的应用范围。 标签中的“PID”、“matlab”、“simulink”、“博文附件”和“多版本适用”进一步细化了内容的关键点。这表示该资源包是博客文章的附加材料,专门针对PID控制器在MATLAB的Simulink环境中进行仿真实验。多

    MATLAB代码:考虑P2G和碳捕集设备的热电联供综合能源系统优化调度模型 关键词:碳捕集 综合能源系统 电转气P2G 热电联产 低碳调度 参考文档:Modeling and Optimiza

    MATLAB代码:考虑P2G和碳捕集设备的热电联供综合能源系统优化调度模型 关键词:碳捕集 综合能源系统 电转气P2G 热电联产 低碳调度 参考文档:《Modeling and Optimization of Combined Heat and Power with Power-to-Gas and Carbon Capture System in Integrated Energy System》完美复现 仿真平台:MATLAB yalmip+gurobi 主要内容:代码主要做的是一个考虑电转气P2G和碳捕集设备的热电联供综合能源系统优化调度模型,模型耦合CHP热电联产单元、电转气单元以及碳捕集单元,并重点考虑了碳交易机制,建立了综合能源系统运行优化模型,模型为非线性模型,采用yalmip加ipopt对其进行高效求解,该模型还考虑了碳排放和碳交易,是学习低碳经济调度必备程序 代码非常精品,注释保姆级 这段代码是一个用于能源系统中的综合能源系统(Integrated Energy System)建模和优化的程序。它使用了MATLAB的优化工具箱和SDP(半定规划)变量来定义决策变

    中国飞行器设计大赛圆筒权重文件

    中国飞行器设计大赛圆筒权重文件

    java毕设项目之ssm社区文化宣传网站+jsp(完整前后端+说明文档+mysql+lw).zip

    项目包含完整前后端源码和数据库文件 环境说明: 开发语言:Java 框架:ssm,mybatis JDK版本:JDK1.8 数据库:mysql 5.7 数据库工具:Navicat11 开发软件:eclipse/idea Maven包:Maven3.3 服务器:tomcat7

    风光储、风光储并网直流微电网simulink仿真模型 系统由光伏发电系统、风力发电系统、混合储能系统(可单独储能系统)、逆变器VSR+大电网构成 光伏系统采用扰动观察法实现mppt控

    风光储、风光储并网直流微电网simulink仿真模型。 系统由光伏发电系统、风力发电系统、混合储能系统(可单独储能系统)、逆变器VSR+大电网构成。 光伏系统采用扰动观察法实现mppt控制,经过boost电路并入母线; 风机采用最佳叶尖速比实现mppt控制,风力发电系统中pmsg采用零d轴控制实现功率输出,通过三相电压型pwm变器整流并入母线; 混合储能由蓄电池和超级电容构成,通过双向DCDC变器并入母线,并采用低通滤波器实现功率分配,超级电容响应高频功率分量,蓄电池响应低频功率分量,有限抑制系统中功率波动,且符合储能的各自特性。 并网逆变器VSR采用PQ控制实现功率入网 以下是视频讲解文案: 接下来我来介绍一下 就是这个风光储直流微电网 整个仿真系统的一些架构啊 然后按照需求呢正常的讲一些 多讲一些 就是储能的这块的 还有这个并网的 三相两电瓶调的这个 并网继变器的这个模块 首先就是来介绍一下呃 整个系统的一个架构 你可以看到这个系统的架构 分别有四大部分组成 最左边的这块就是混合储能啊 这边这个是蓄电池 这个超级电容 他们都是

    ajax发请求示例.txt

    ajax发请求示例.txt

    深圳建筑安装公司“电工安全技术操作规程”.docx

    深圳建筑安装公司“电工安全技术操作规程”

    220) Vinkmag - 多概念创意报纸新闻杂志 WordPress v5.0.zip

    220) Vinkmag - 多概念创意报纸新闻杂志 WordPress v5.0.zip

    智力残疾评定标准一览表.docx

    智力残疾评定标准一览表.docx

    MDIN380 SDI转VGA 转LVDS VGA转SDI 高清视频处理 MDIN380芯片 PCB代码方案资料 3G-SDI转VGA ?3G-SDI转LVDS ?高清视频 MDIN380、GV76

    MDIN380 SDI转VGA 转LVDS VGA转SDI 高清视频处理 MDIN380芯片 PCB代码方案资料 3G-SDI转VGA ?3G-SDI转LVDS ?高清视频 MDIN380、GV7601 芯片方案(PCB图和源码)。 此方案是韩国视频处理芯片MDIN380的整合应用方案。 3G-SDI转VGA或3G-SDI转LVDS。 方案共有两块电路板(一块底板,一块MDIN380核心板 四层板)。 MDIN380和GV7601 都是BGA封装,最好有焊接BGA经验才拿。 另外有视频处理方面其它需要可联系我定制开发。 其它视频格式转,视频图像分割、拼接等可定制开发。 方案资料含有源码、PCB图。 方案已有成熟产品在应用。 注意该资料没有原理图,只有PCB图。 代码环境编译KEIL4。 画图软件Protel99、AD10。 电子文档资料

    YOLO算法-锡罐-牙罐-盖子打开数据集-179张图像带标签-锡罐-牙罐-盖子打开.zip

    YOLO系列算法目标检测数据集,包含标签,可以直接训练模型和验证测试,数据集已经划分好,包含数据集配置文件data.yaml,适用yolov5,yolov8,yolov9,yolov7,yolov10,yolo11算法; 包含两种标签格:yolo格式(txt文件)和voc格式(xml文件),分别保存在两个文件夹中,文件名末尾是部分类别名称; yolo格式:<class> <x_center> <y_center> <width> <height>, 其中: <class> 是目标的类别索引(从0开始)。 <x_center> 和 <y_center> 是目标框中心点的x和y坐标,这些坐标是相对于图像宽度和高度的比例值,范围在0到1之间。 <width> 和 <height> 是目标框的宽度和高度,也是相对于图像宽度和高度的比例值; 【注】可以下拉页面,在资源详情处查看标签具体内容;

    G120 EPOS基本定位功能关键点系列-堆垛机报F7452追踪原因.mp4

    G120 EPOS基本定位功能关键点系列_堆垛机报F7452追踪原因.mp4

    java毕设项目之ssm亚盛汽车配件销售业绩管理统+jsp(完整前后端+说明文档+mysql+lw).zip

    项目包含完整前后端源码和数据库文件 环境说明: 开发语言:Java 框架:ssm,mybatis JDK版本:JDK1.8 数据库:mysql 5.7 数据库工具:Navicat11 开发软件:eclipse/idea Maven包:Maven3.3 服务器:tomcat7

    zigbee CC2530无线自组网协议栈系统代码实现协调器与终端基于GenericApp的无线收发例程.zip

    1、嵌入式物联网单片机项目开发例程,简单、方便、好用,节省开发时间。 2、代码使用IAR软件开发,当前在CC2530上运行,如果是其他型号芯片,请自行移植。 3、软件下载时,请注意接上硬件,并确认烧录器连接正常。 4、有偿指导v:wulianjishu666; 5、如果接入其他传感器,请查看账号发布的其他资料。 6、单片机与模块的接线,在代码当中均有定义,请自行对照。 7、若硬件有差异,请根据自身情况调整代码,程序仅供参考学习。 8、代码有注释说明,请耐心阅读。 9、例程具有一定专业性,非专业人士请谨慎操作。

    基于小程序的小区物业新冠疫情物资管理平台小程序源代码(java+小程序+mysql+LW).zip

    系统可以提供信息显示和相应服务,其管理小区物业新冠疫情物资管理平台信息,查看小区物业新冠疫情物资管理平台信息,管理小区物业新冠疫情物资管理平台。 项目包含完整前后端源码和数据库文件 环境说明: 开发语言:Java JDK版本:JDK1.8 数据库:mysql 5.7 数据库工具:Navicat11 开发软件:eclipse/idea Maven包:Maven3.3 部署容器:tomcat7 小程序开发工具:hbuildx/微信开发者工具

    亲测源码云赏V7.0微信视频打赏系统源码已测试完整无错版

    云赏V7.0包括V6的所有功能外,全新UI设计,代理可以选择8种风格,添加后台统计等多种功能。 1基本设置(网站基础信息配置、包括主域名、防封尾缀、url.cnt.cn短连接接口可切换); 2转跳域名(10层防守转跳,都输入的话,都会转跳到对应的地方在跳回来,在随机取用落地); 3落地域名(添加落地域名及设置默认落地域名); 4视频列表(添加视频批量添加外链视频给代理们获取); 5代理推广:代理使用推广链接发展下级代理,后台设置提成); 6代理列表(生成邀请码注册,手动添加代理); 7提现记录(用于结算代理们的提现); 8余额记录(记录代理的余额变动); 9订单记录(记录打赏数,今日收入)。 测试环境: Nginx 1.18+PHP56+MySQL5.6,详细教程见文件内文字教程。 后台账号:admin 密码:admin888

    深圳建设施工项目易燃、易爆、有毒、有害物品管理制度.docx

    深圳建设施工项目易燃、易爆、有毒、有害物品管理制度

Global site tag (gtag.js) - Google Analytics