Ruby In Steel Archives

Back to -Ruby In Steel Archives

Ruby On Rails Development In Steel

How to create and maintain Rails applications

Here is a short guide to some of Steel’s features for programming Ruby On Rails in Visual Studio...

NOTE:This is an old article. It describes a beta release Steel 0.7 of our free Ruby IDE. The tools and debugger in the current version of the commercial Developer Edition of Ruby In Steel have been considerably enhanced. Please check the links on the Front Page for all the latest information.

RAILS NEW PROJECT WIZARD

Step 1

To create a new Ruby On Rails project…
- Select the File menu, New, Project, Rails
- Enter project name - e.g. “MyBlog” in the Name Field
- Optionally, select ‘Create Directory For Solution’
- Click OK

Step 2

In the Create Rails Project dialog, select a database server and one or more database types to be generated. Enter a name for the application, a user name which should previously have been set up in your database server, a database password if you have one and a host. Currently we have ’built in’ support for MySQL and SQL Server. More database options will be added later. You can, of course, use any database server you wish - just create a database in the usual way and edit the .yml file of your application.

Note: the database types correspond to the three types traditionally used by Rails. You may select one or more of these. Steel automatically generates databases with the suffixes _development, _production and _test and these suffixes are appended to the application name. For example, if you have name the application: MyRailsApp and selected Development and Test database types, Steel will create two databases named MyRailsApp_development and MyRailsApp_test. All the necessary configuration information will also be written into a database.yml file as required by Rails.

Examples…

- MySQL

(Note: You must have MySQL installed; it can be downloaded from http://dev.mysql.com/). This example assumes that you have set up a user name (here ‘root’) and a host (here ‘localhost’). In this example, it is assumed you have left the database password unspecified. Here I have named the application ‘MyBlog’ and I have selected the Development, Production and Test database types. This is what you would enter into the Create Rails Project dialog:

- SQL Server

(Note: You must have SQL Server installed; a free edition called SQL Server Express can be downloaded from http://msdn.microsoft.com/vstudio/express/sql/). This example assumes that you have set up a user name (here ‘huw’), a password (also ‘huw’ and a host (here ‘.\SQLEXPRESS’). Here I have named the application ‘MyBlog’ and I have selected the Development database type only. This is what you would enter into the Create Rails Project dialog:

All being well, Steel will display all the files and directories of your new Rails application in the Solution Explorer. If you encounter any problems you may want to check that you have installed the database server correctly and that the user name, password and host which you entered into the Rails Project dialog match the details which you previously set up in the database server. If Steel was unable to find the database server, check that you have set up the path to its directory. Paths can be configured using the Steel Settings dialog (see below). Database creation will also fail if you attempt to create a database with a name which already exists. Check the Visual Studio Output pane (press CTRL+W, O) to see any error messages.

RAILS SOLUTION EXPLORER

The Solution Explorer in Steel displays all the directories and files created by Rails, including Ruby, rhtml, yml, html and JavaScript files.

- SHOW ALL FILES

Normally the Solution Explorer does not display certain files which are likely to be irrelevant to a Ruby or Rails application (these include the Visual Studio and Steel solution and project files – the extensions .sln, .suo and .stproj), files with no extension and files with the extension .log. You can force the display of all files in the application directories by selecting Show All Files from the Project menu; this also expands all branches of the Solution Explorer. Click the menu item again to resume the default view.

OPEN COMMAND PROMPT IN DIRECTORY

You may sometimes want to run programs or scripts from a specific directory in your project. To do this, right-click a directory or a file in the Solution Explorer and select ‘Command Prompt’. This will open a command window in the selected directory.

IMPORT/UPGRADE RAILS AND RUBY PROJECTS

For advice on importing or upgrading older Steel projects or existing Rails projects - see the separate article on Importing and Upgrading.

RHTML COLOURING AND COLLAPSING

Rails .rhtml files feature syntax sensitive code colouring. Not only are HTML elements coloured but so too is any embedded Ruby code. Code collapsing in .rhtml files is performed on HTML tags. In pure Ruby files, code collapsing is performed on Ruby language constructs (see The Editor and Console).

BUILD TO CHECK FOR SYNTAX ERRORS

Build Solution F6 and Rebuild Solution examine all Ruby and rhtml files in a project and reports on any syntax errors located. You can view the progress of the error checking in the Output window. Errors are reported in the Error List. Build only checks those files which have been changed since a previous Build; Rebuild checks all files.

As part of the Build process, Steel creates a \SyntaxCheck directory containing a record of all the documents built (these are 0-length files). You can remove this directory by selection Clean Solution from the Build menu.

RAILS TOOLBAR AND MENU

There is now a Rails toolbar and a matching Rails menu, each of which contains icons which can be used to run various command. The toolbar can be displayed by selecting it from the View/Toolbars menu. The Rails icons are:

- Start Server

In the current release, this starts the WEBrick server. Alternatively, you can use any other server of your choice by starting it in the usual way. We shall be adding more ’dedicated’ server support options in later releases. The Start Server Dialog displays the port number for the server. If you wish to use a different port, edit the number. If you wish to use the new number in future, click the ‘Make Default’ check box. Click Start to run the server.

- Generate

This displays a dialog from which you can run various scripts. Currently these are:

  • Controller
  • Model
  • Scaffold
  • Other

When Controller, Model or Scaffold are selected, you need to enter one or more arguments (e.g. a name such as ‘MyBlog’) in the Value field. When Other is selected, you should enter the name of the script to run in the Action field and any arguments in the Value field. Then click OK.

- Synchronize

In certain special cases, it may be possible for the Solution Explorer to get ‘out of synch’ with the files and directories in your application directory. This may be so, for example, if you create files using an external editor or if you run scripts from the command prompt. If this happens, click ‘Synchronize’ to update the Solution Explorer.

- Gems

Run this when you want to install a Ruby gem package. Enter the name of the Gem in the field then click OK to attempt to locate and install a Gem.

INTEGRATED SQL SERVER DEVELOPMENT

If you use Microsoft’s SQL Server (or the free SQL Express) as your database server you can create and edit tables right from within the Visual Studio environment itself. Open the database in the Server Explorer…

..and edit the tables and column properties…

CONFIGURE STEEL FOR RAILS

You may need to set the path to your Ruby interpreter or to a MySQL or SQL Server database server. When a Steel project is open, set these paths using the Steel Settings dialog which is available by selecting Configure Steel from The Tools menu.

COLOUR CODING OPTIONS

Steel has always provided syntax sensitive colouring for Ruby, which adopts the global colouring options assigned in Visual Studio. Version 0.7 of Steel also supplies some Ruby and Rails-specific colouring options such as Ruby Symbol and Rails attribute. These colours can be set in the Options dialog (Fonts and Colors) available from the Tools menu.

FILE PROPERTIES

In The Properties panel you can set properties for a Ruby file which is currently open in the editor.

The available properties are:

Property Description
Flags Flags to pass to Ruby.exe such as –help, -w or —version
Arguments Arguments to pass to your program
Build Action (Some options for a future release : to exclude a file from Build, select None)
Load Paths specify $LOAD_PATH ; this is a semicolon delimited list (equivalent to the –I flag)
Require Files a semicolon delimited list of required files (equivalent to the –r flag)

PROJECT PROPERTIES

The Project Build Properties are set via the project’s Property Page. These are similar to the properties you can apply to an individual Ruby or Rails file, but only apply when the project is ‘built’. As mentioned above, building a Steel project currently involves syntax checking the Ruby program files and/or Rails HTML pages: the files are not actually run. However, there is also an ‘after-build’ task which in the example shown runs some tests.

This property page is taken from the RubyCLR Bridge by John Lam. We just set up the Visual Studio solution to include two projects – the C++ project and the main Ruby files...

Building the project constructs the C++ dll, checks the Ruby files for Syntax errors and, lastly, runs the tests.

Bookmark and Share   Keywords:  ide  rails
© SapphireSteel Software 2014