Making New Thl Ror Apps

THL Toolbox > Developers' Zone > Ruby On Rails Development > Making New THL Ror Apps

Making a new THL Application in RoR

Contributor(s): Andres Montano.

Andres Montano has developed a a plugin called THDL_integration, to facilitate the task of giving a Ruby on Rails application the THL look and feel. It is very easy to use. You only need to make the two calls (header & footer) from the layout and one redefine (side_column_links).

You can find the basic app on the svn server (external link: http://ndlb.svn.sourceforge.net/svnroot/ndlb/portal/ror/basic_authenticated_app/) along with a long README which is included below. This should help a developer get started quickly.

Welcome to the Basic Authenticated App

This application is meant to be the starting point for new Ruby on Rails applications for THL. It consists of already implemented basic functionality so that the developer can focus on solving the actual problem.

It includes:

  • THL look and feel
  • Open id authentication
  • User management with roles and privileges
  • Support for complex scripts
  • Multilingual interface

Getting Started

Checking out the basic authenticated app from the repository is probably not a good idea, unless you want to change the actual templates for new applications. Doing an svn export of the application for then doing an svn import would screw up some files (for instance the plugins which is suggested here to leave as svn externals, would become svn internals, etc.).

1. So my suggested way of starting is to copy the basic_authenticated_app folder in the repository into another folder with the name of the new application.

For instance, if you want to build a timeline application do:

svn copy external link: http://ndlb.svn.sourceforge.net/svnroot/ndlb/portal/ror/basic_authenticated_app/ external link: http://ndlb.svn.sourceforge.net/svnroot/ndlb/portal/ror/timeline

2. Now check out the new application. If you are a developer, remember to check out trunk!

svn checkout external link: http://ndlb.svn.sourceforge.net/svnroot/ndlb/portal/ror/timeline/trunk/ timeline

3. The next step is updating the config/database.yml file to setup the database correctly. In our example, we would probably want to change the name of the database to timeline (timeline_development, etc.)

At this point, you DON'T need to go to your database manager to create such db's. We will do that next within rails. Just make sure that the user and password we specify in database.yml WILL have access to such db's. For instance, in my development machine the rubyuser mysql account have full privileges on %_development. This way I know the rubyuser account will be able to access any new development db even if it doesn't exist yet!

This may be quite obvious, but I will say it anyway. DON'T commit the user and password for the production db. Remember this is a public repository and if you do, you are giving everybody access to such db.

4. Now lets create the databases from rails. To create the development db simply run (if you want to do this on the production db, simply add RAILS_ENV=production to all of the next statements):

rake db:create

5. We are using globalize to provide the multilingual views. To create globalize tables, run:

rake globalize:setup

6. Create the rest of the tables by running the migration:

rake db:migrate

7. Now we have to update the roles and privileges. If you see the first migration under db/migrate/001_create_users.rb you will notice that only one user has been created (user 'root', password 'rootdude'). He is a system administrator, but for now a system administrator ONLY has privileges to update roles. So run the server:

script/server

And browse to external link: http://localhost:3000

Next login with user 'root'. You will notice that a link to Roles will appear on the right side navigation. Click on it. Select system administrator -> edit. Under available roles, click "select all" and the ">" button and then save changes. Notice that now you have a lot more links on the right side navigation. As you create new controllers it is a good idea that you create roles for the various kinds of expected users that will change data (end users that are just visiting won't need an account) and when you create new users associate them with the respective roles, i.e. don't make everybody a system administrator!

8. Start developing!

Tips

Try to make all of your controllers RESTful. This will facilitate providing web-services to other applications

To restrict access to a controller, make it inherit from AclController instead of ApplicationController. Only people with the role that has the privileges for each action of that controller will be able to access it. See app/controllers/acl_controller.rb for more information.

See app/helpers/application_helper.rb. There is where you define the side column links, stylesheets and javascript to be used by all controllers in the application. You can override any of the three by redefining its method on the controller's helper.

Provided for unrestricted use by the external link: Tibetan and Himalayan Library