A working example of has_and_belongs_to_many association in Rails 4
This example has two models Student and Project associated using has_and_belongs_to_many.
- launch the rails app and go to http://localhost:3000/students/new for adding students
- Navigate to http://localhost:3000/projects/new for adding new projects and assign existing students to the project
This example now has user authentication feature using Devise gem.
The root of the app now points to the signup page. The operations of New, Edit, and Destroy for Student and Project resource are only available after signing in. Index, and Show work without signing in.
The example has been extended to include testing, starting with unit test
test/models/student_test.rb contains a test "test_without_name"
run the test by executing rake test test_without_name in console
the test will fail if the validation line validates :name, presence: true
in app/models/student.rb has been commented. The test will pass if comment symbol # is removed in the model.