Tuesday, May 28, 2013

Life without scaffolding

After I read the tutorial from Nettuts+ , here are parts of the key step for creating a web-app without rails' scaffolding.

Creating the new project

Type in the following command
where PROJECT_NAME is the name of the new project, please notice that the -T argument tells rails not to generate the unit-testes automatically.

Installing Rspec and Capybara

Open the Gemfile inside the generated project and append the following lines: Save the file and use the following commands to install the necessary gems and initialize the /spec directory
And we can run the specs (aka unit-tests) with this command If you encounter problems like: 'undefined method `visit' for #<RSpec::Core::ExampleGroup...' while using Capybara methods, try to put the following lines in /spec/spec_helper.rb, inside the config block. (reference)

Creating Controllers

To generate a controller, for example, Tasks (rails use plural form to name controllers): Then we setup the routes for the generated controller by adding the following line to /config/routes.rb Verify the routing by the following command To add a view, for example 'index', to our controller, open /app/controllers/task_controller.rb and remember to add the template file for our view in /app/views/tasks/index.html.erb

Creating Models

To generate a model, for example, Task with 2 attributes: desc (text) and done (boolean) here is the reference of available attribute types
After that perpare our database using the following commands

Tuesday, May 21, 2013

Let's get wet

After considering the recommendations from my co-worker, I decided to learn how to build a web-app using the Ruby on Rails, since it seems to be a fast and complete solution.

In order to get started on the win32 platform, I follows the steps in the offical guide http://guides.rubyonrails.org/getting_started.html, and here is a summary of the key-steps for setting up the environment.
  • Download the ruby 1.9.3-p429 installer and DevKit-tdm-32-4.5.2-20111229-1559-sfx.exe from http://rubyinstaller.org/ (I've tried the 2.0.0 version but there are some problems on the sqlite3 gem).
  • After the ruby installation is completed, extract the all contents (with 7-zip) in the DevKit package to C:\DevKit, and then execute the followings using the Ruby's command prompt
  • When the DevKit is configurated, restart the Ruby's command prompt.
  • Then execute to install Ruby on Rails.
Be patient and you are ready to travel on Rails :-)

References: