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

No comments: