SapphireSteel Software

 

  -  
     
     
     
  -  
     
     
     
  -  
     
     
     
  -  
     
     
     
  -  
     
     
     
     

 

  rss
RSS (SITE)
 
  rss
RSS (BLOG ONLY)
 
   
 
 
     

 

Section :: Ruby In Steel Archives
- Format For Printing...
Getting Started With Steel...

Ruby On Rails Development In Steel

by Huw Collingbourne and Dermot Hogan
How to create and maintain Rails applications
Friday 7 July 2006.
 
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.

AddThis Social Bookmark Button

Forum

  • Ruby On Rails Development In Steel
    16 July 2006, by Jules

    Wow this is so cool. Its Sunday evening, and I have just downlaoded and installed Ruby, Rails, Steel, MySQL Server and SQL Server to start playing with this stuff.

    I have successfully set up and able to generate the Application Directories etc, and Started Server etc. Created a basic Table in SQL Server, with id and other attributes.

    Just having a bit of a problem with my first basic application with the Scaffold Generator against database table. Not clear what the parameters to the scafold Generator are when generating against products database table. I would have expected two parameters:- Product Admin ie. the Model name and the Controller. I seem to get a Model product product.rb but no controller file for admin. So some more clarfication on the Generator functions, and how the parameters correspond to the native Rails Generators would be helpful.

    Anyway Time for Bed !

    • Ruby On Rails Development In Steel
      17 July 2006, by Huw

      A few examples of using Generators...

      - To create a Controller called Blog, select Controller and enter Value: Blog
      - To generate a Model called Post, select Model and enter Value: Post
      - To generate a Scaffold for Post in your Blog, select scaffold and enter Value: Post Blog

      The above examples are all taken from the well-known Ruby On Rails weblog screencast: http://www.rubyonrails.com/screencasts

      Our generators run the equivalent scripts - e.g.

      ruby ./script/generate [Action = controller/model/scaffold]; [Value = prameters]

      So the first example above, if run from the commandline would be:

      ruby ./script/generate controller Blog

      We’ll be adding a tutorial to the site shortly to guide you through a simple weblog project using Ruby In Steel.

      I hope that helps...

      best wishes

      Huw

      • Ruby On Rails Development In Steel
        17 July 2006, by Jules

        Yes working through a worked sample would be good (preferably against standard MS SQL Server).

        I am pretty sure my problems are due to SQL Database connection setup. I have got the Scaffold generator to work OK against a MySQL database Table, so it has something to do with database Connection string against my SQL Server database. I am trying to get to work with SQL Server Authentification Username and Password, rather than Windows authentification or the sa account.

        What would be nice would be a RAILS - TEST Database Connection button

        My database.yml looks like:-

        # SQL Server

        development:

        adapter: sqlserver

        host: localhost

        database: SQL_RAILS

        password: Helena

        Cheers

        Jules

        • Ruby On Rails Development In Steel
          17 July 2006, by Huw

          I’m trying to get as much documentation online as quickly as I can and be assured that a Rails walkthrough is a priority. I’ll get a Flash movie online this week to guide you through a Rails blog in Ruby In Steel. I’ll try to get a written step-by-step guide with explanations by next week.

          best wishes

          Huw

          • Ruby On Rails Development In Steel
            18 July 2006, by Jules
            Cool, sorry if I am being a pain, but it is just that I am pretty excited by this stuff and if I missed saying this before - This is one great tool development ! Such a great achievement. Never really got into ASP.NET and that ADO stuff - But with RoR mixed with the VS environment generating RoR solutions is going to be so much fun.
            • Ruby On Rails Development In Steel
              22 July 2006, by Jules

              Excellent, I have got my SQL version to work with Scaffold. The main chnage I made was to database.yml, where I have "User Id:" instead of "usernaem. I also notice that I don’t seem to need to have a host: field for the generators and execution to work.

              A couple of other observations.

              a) I note that the database should not exist before I try to generate the RAILS application. Steel generates and creates the database in SQL. This seems a bit of an odd way round, because typically the databse exist before the RAILS application generated. (My MySQL version didn’t seem to mind)

              b) The Scaffold Generator with my SQL Server version, generates the files, but does not inlcude the list, edit view files etc in the VS project. ( My MySQL version does.)

              Anyway happy gnerating and executing RAILS solutions with SQL Server now.

              Jules

  • Ruby On Rails Development In Steel
    9 July 2006
    Will it be possible to switch on the Server? I don’t like WebBrick, I prefer Mongrel...you may want to think about making it the default server also.
    • Ruby On Rails Development In Steel
      10 July 2006, by Dermot

      The Start Server mechanism is pretty simple right now. It just runs a cmd file with a user specified port parameter which runs the Rails script/server file. If you change that, it will run whatever server you want.

      The idea really was to allow a developer to quickly start a server on any port to test something out quickly.

      The Steel IDE doesn’t require that you use any particular server. We might get this more integrated a bit later on (running the Web server internally to VS, say) so that all the output from the server goes into a specific Visual Studio Output pane.

      I’m still thinking about Mongrel, etc.

    • Ruby On Rails Development In Steel
      17 July 2006, by Jules

      Hello

      This looks great and I set up the environment OK. I am a little confused however ont eh Gnerator functions. For my first project, I tried to use Scaffold Gnerator against a Database Table (Model) - But its not clear how the Scaffold Generator parameters Model and Controler are specified. When i run it against the Table name, I get a Model ruby file but no Controller is generated.

      Could you clarifiy how the Generator Values/ parameters are used.

      Looking Great

      Jules

      • Ruby On Rails Development In Steel
        30 August 2006
        The same thing happened for me. Only the model showed up.
        • Ruby On Rails Development In Steel
          30 August 2006, by Huw

          The generator dialogs simply run standard Rails scripts so I’m not sure what the problem can be. Have you checked the RubyIn Steel manual which goes through the details of the script and parameter usage of the Generator dialog. I’d be grateful if you can check this and let us know if this solves the problem. If not, please contact Support and we’ll go through all the details with you. Naturally, if you are still experiencing a problems, we will want to fix it. ;-)

          best wishes

          Huw

 

© 2008 SapphireSteel Software. All rights reserved