Creating the new project
Type in the following commandwhere 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 directoryAnd 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.erbCreating Models
To generate a model, for example, Task with 2 attributes: desc (text) and done (boolean) here is the reference of available attribute typesAfter that perpare our database using the following commands
No comments:
Post a Comment