User Tools

Site Tools


building_a_basic_ruby_on_rails_application

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
building_a_basic_ruby_on_rails_application [2024/09/01 04:37] – n′t hc9building_a_basic_ruby_on_rails_application [2024/09/02 23:01] (current) – ' hc9
Line 15: Line 15:
 </code> </code>
  
-The first command creates our projects directory tree under the '''~/html/bookmarks<nowiki>'</nowiki>'' directory. Then we create a symlink from this directory, to '''~/html/rails<nowiki>'</nowiki>'' so that the SDF utility scripts will be able to find, and work with this project. ( [[#appendix_asdf_utility_scripts| More info]] )+The first command creates our project's directory tree under the '''~/html/bookmarks<nowiki>'</nowiki>'' directory. Then we create a symlink from this directory, to '''~/html/rails<nowiki>'</nowiki>'' so that the SDF utility scripts will be able to find, and work with this project. ( [[#appendix_asdf_utility_scripts| More info]] )
  
-The '''--database=sqlite3<nowiki>'</nowiki>'' argument to the '''rails<nowiki>'</nowiki>'' executable, informs Rails to configure the new project to use an SQLite3 database backend. If you have 'dba' membership then you can use MySQL as your backend by substituting '''sqlite3<nowiki>'</nowiki>'' with '''mysql<nowiki>'</nowiki>''. This tutorial will however focus in using SQLite3 as it is available to all MetaARPA members. If you are going to use MySQL as your database backend, then youll have to read [[#appendix_bconfiguring_a_database|this]] in order to configure your backend properly.+The '''--database=sqlite3<nowiki>'</nowiki>'' argument to the '''rails<nowiki>'</nowiki>'' executable, informs Rails to configure the new project to use an SQLite3 database backend. If you have 'dba' membership then you can use MySQL as your backend by substituting '''sqlite3<nowiki>'</nowiki>'' with '''mysql<nowiki>'</nowiki>''. This tutorial will however focus in using SQLite3 as it is available to all MetaARPA members. If you are going to use MySQL as your database backend, then you'll have to read [[#appendix_bconfiguring_a_database|this]] in order to configure your backend properly.
  
-The final command changes your working directory to your new projects′ root. The rest of the commands in this tutorial rely on you being at this location in order to execute correctly.+The final command changes your working directory to your new projectsroot. The rest of the commands in this tutorial rely on you being at this location in order to execute correctly.
  
 ===== Building The Data Model ===== ===== Building The Data Model =====
  
-Now we are sitting in our nice new Rails projects root directory, we can start building our application. The most important thing in any database driven application like this one, is the data model. It specifies what data our application interacts with, and //how// we interact with it.+Now we are sitting in our nice new Rails project's root directory, we can start building our application. The most important thing in any database driven application like this one, is the data model. It specifies what data our application interacts with, and //how// we interact with it.
  
 In this application, we only have one data type, that is a 'Link', this link must have a name, some descriptive information and the target URI. Normally at this stage you'd have to roll-up your sleeves and write one of those fugly SQL statements to create your table. Not us, Rails has cunningly abstracted database interaction for us, so no more SQL! In order to create our mode we must run this command: In this application, we only have one data type, that is a 'Link', this link must have a name, some descriptive information and the target URI. Normally at this stage you'd have to roll-up your sleeves and write one of those fugly SQL statements to create your table. Not us, Rails has cunningly abstracted database interaction for us, so no more SQL! In order to create our mode we must run this command:
Line 53: Line 53:
 </code> </code>
  
-Now weve specified our '''links<nowiki>'</nowiki>'' tables structure. We have to commit the revision in order to create the table. To do this execute the following:+Now we've specified our '''links<nowiki>'</nowiki>'' table's structure. We have to commit the revision in order to create the table. To do this execute the following:
  
 <code> <code>
Line 59: Line 59:
 </code> </code>
  
-Going into the details of this command is way outside the scope of this document, I wouldnt have used it in this tutorial if it wasnt for it being such an easy way to generate a database across different backends.+Going into the details of this command is way outside the scope of this document, I wouldn't have used it in this tutorial if it wasn't for it being such an easy way to generate a database across different backends.
  
  ]]  ]]
Line 72: Line 72:
 </code> </code>
  
-Right, those two commands did quite a bit. The first one generated a basic set of HTML templates and application logic. The second command started a web server, written in Ruby, running on a port that was specified from your userid. Youll notice on the second line of output from the '''server <nowiki>'</nowiki>'' script, the address that it has bound itself too, along with the port number ( your user id ) it is running on in standard URI format.+Right, those two commands did quite a bit. The first one generated a basic set of HTML templates and application logic. The second command started a web server, written in Ruby, running on a port that was specified from your userid. You'll notice on the second line of output from the '''server <nowiki>'</nowiki>'' script, the address that it has bound itself too, along with the port number ( your user id ) it is running on in standard URI format.
  
-So, open up a web browser, and point it to '''http://sverige.freeshell.org:[ YOUR USER ID ]<nowiki>'</nowiki>'' substituting your user id. Your browser should open 'Ruby on Rails: Welcome aboard′ page. This just indicates that the Rails environment and server are running. Now, go back to your browsers′ address bar, and append '''/links<nowiki>'</nowiki>'' after your user id. Your browser should now show a rather rubbish looking list view, with no elements.+So, open up a web browser, and point it to '''http://sverige.freeshell.org:[ YOUR USER ID ]<nowiki>'</nowiki>'' substituting your user id. Your browser should open 'Ruby on Rails: Welcome aboardpage. This just indicates that the Rails environment and server are running. Now, go back to your browsersaddress bar, and append '''/links<nowiki>'</nowiki>'' after your user id. Your browser should now show a rather rubbish looking list view, with no elements.
  
-At this point it will probably be a good idea to play around and add some items as well need them for the next sections. Besides, I need to make myself a drink ...+At this point it will probably be a good idea to play around and add some items as we'll need them for the next sections. Besides, I need to make myself a drink ...
  
 ===== To Be Continued ... ===== ===== To Be Continued ... =====
Line 86: Line 86:
 There are two utility scripts written specifically for Rails applications on SDF. The first 'ror' toggles whether the Rails project under '''~/html/rails<nowiki>'</nowiki>'' has it's server started when the system boots. The second script 'railsctl', is start/stop daemon, which starts or stops the Rails project located in the standard SDF project location. There are two utility scripts written specifically for Rails applications on SDF. The first 'ror' toggles whether the Rails project under '''~/html/rails<nowiki>'</nowiki>'' has it's server started when the system boots. The second script 'railsctl', is start/stop daemon, which starts or stops the Rails project located in the standard SDF project location.
  
-As you may want to play with multiple Rails projects, it doesnt really matter where you put them, or what you call them. But if you plan on using the SDF utility scripts, which is a good idea if you want to host your project, then it's probably a good idea to symlink your current project directory to '''~/html/rails<nowiki>'</nowiki>''+As you may want to play with multiple Rails projects, it doesn't really matter where you put them, or what you call them. But if you plan on using the SDF utility scripts, which is a good idea if you want to host your project, then it's probably a good idea to symlink your current project directory to '''~/html/rails<nowiki>'</nowiki>''
  
 ===== Appendix B: Configuring A Database ===== ===== Appendix B: Configuring A Database =====
building_a_basic_ruby_on_rails_application.1725165451.txt.gz · Last modified: 2024/09/01 04:37 by hc9