ruby_on_rails
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
ruby_on_rails [2021/03/15 02:30] – fix wiki link to making a website, clean up traditional link peteyboy | ruby_on_rails [2024/09/16 07:08] (current) – pg” hc9 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Ruby on Rails on SDF ====== | ||
+ | |||
+ | ===== What is Rails? ===== | ||
+ | |||
+ | [[http:// | ||
+ | |||
+ | ===== Prerequisites ===== | ||
+ | |||
+ | * You must be a MetaARPA member to use Rails (see [[http:// | ||
+ | * You should figure out your [[meta port allocation| allocated port]] in the metaarray | ||
+ | * Most Rails applications use a database, so you'll probably want dba membership as well (see [[http:// | ||
+ | |||
+ | ===== Getting started ===== | ||
+ | |||
+ | **Step 1:** Run “mkhomepg” if you have not already done so (see the [[Building a Website on SDF]] tutorial for more information on the “mkhomepg” command). | ||
+ | |||
+ | **Step 2:** Use the rails command to construct the base for your new rails application: | ||
+ | |||
+ | $ cd $HOME/html | ||
+ | $ rails rails | ||
+ | create | ||
+ | create | ||
+ | create | ||
+ | create | ||
+ | create | ||
+ | create | ||
+ | create | ||
+ | create | ||
+ | create | ||
+ | create | ||
+ | create | ||
+ | create | ||
+ | create | ||
+ | create | ||
+ | create | ||
+ | create | ||
+ | create | ||
+ | create | ||
+ | create | ||
+ | create | ||
+ | create | ||
+ | create | ||
+ | create | ||
+ | create | ||
+ | create | ||
+ | create | ||
+ | create | ||
+ | create | ||
+ | create | ||
+ | create | ||
+ | create | ||
+ | create | ||
+ | create | ||
+ | create | ||
+ | create | ||
+ | create | ||
+ | create | ||
+ | create | ||
+ | create | ||
+ | create | ||
+ | create | ||
+ | create | ||
+ | create | ||
+ | create | ||
+ | create | ||
+ | create | ||
+ | create | ||
+ | create | ||
+ | create | ||
+ | create | ||
+ | create | ||
+ | create | ||
+ | create | ||
+ | create | ||
+ | create | ||
+ | create | ||
+ | create | ||
+ | create | ||
+ | create | ||
+ | create | ||
+ | create | ||
+ | create | ||
+ | create | ||
+ | create | ||
+ | create | ||
+ | create | ||
+ | create | ||
+ | create | ||
+ | create | ||
+ | create | ||
+ | create | ||
+ | create | ||
+ | |||
+ | It has become SDF policy to have the project that you want to be served under ‘$HOME/ | ||
+ | |||
+ | **step 3:** | ||
+ | |||
+ | Start the webrick server on your [[meta port allocation |meta allocated port]] that is equal to your //uid ((Example: | ||
+ | |||
+ | $ id | ||
+ | uid=< | ||
+ | |||
+ | // Note: if you do not see metaARPA here you're not in the metaARPA group and Rails won't work for you. //))// : | ||
+ | |||
+ | $ railsctl start | ||
+ | - or - | ||
+ | $ ruby $HOME/ | ||
+ | => Booting WEBrick... | ||
+ | => Rails application started on http:// | ||
+ | => Ctrl-C to shutdown server; call with --help for options | ||
+ | |||
+ | Then point your browser at ''< | ||
+ | |||
+ | ===== Hello, world of Rails! ===== | ||
+ | |||
+ | Rails is a Model-View-Controller framework. Rails accepts incoming requests from a browser, decodes the request to a controller, and calls an action method in that controller. The controller then invokes a particular view to display the results to the user. The good news is that Rails takes care of most of the internal plumbing that links all these actions. To write our simple Hello, World! application, | ||
+ | |||
+ | In the same way that we used the rails command to create a new Rails application, | ||
+ | |||
+ | $ ruby $HOME/ | ||
+ | exists app/ | ||
+ | exists app/ | ||
+ | create app/ | ||
+ | exists test/ | ||
+ | create app/ | ||
+ | create test/ | ||
+ | create app/ | ||
+ | |||
+ | The script logs the files and directories it examines, noting when it adds new Ruby scripts or directories to your application. For now, we're interested in one of these scripts and (in a minute) the new directory. The source file we'll be looking at is the controller. You'll find it in the file app/ | ||
+ | |||
+ | class SayController < ApplicationController | ||
+ | end | ||
+ | |||
+ | Pretty minimal, eh? SayController is an empty class that inherits from ApplicationController, | ||
+ | |||
+ | Let's add an action called hello to our say controller. Adding a hello action means creating a method called hello in the class SayController. But what should it do? For now, it doesn' | ||
+ | |||
+ | class SayController < ApplicationController | ||
+ | def hello | ||
+ | end | ||
+ | end | ||
+ | |||
+ | Now let's try calling it. Navigate to the URL ''< | ||
+ | |||
+ | It might be annoying, but the error is perfectly reasonable (apart from the weird path). We created the controller class and the action method, but we haven' | ||
+ | |||
+ | <file html hello.rhtml> | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | Save the file '' | ||
+ | |||
+ | ===== Maintenance and Utility Scripts ===== | ||
+ | |||
+ | There are currently two main scripts that MetaARPA members can run to manage their RoR instance. The first is //ror// which is used to toggle automatic startup of your RoR instance upon system boot. The second is // | ||
+ | |||
+ | [[http:// | ||