- Rails 4.2.5
- ruby 2.3.4p301
- Cloud9 ide
- clone the project in a rails workspace in Cloud9
- run "rake db:migrate"
- Then to run the server type "rails s -b $IP -p $PORT"
-
Model
- Article
- Category
- User
-
Database Tables
- Articles Columns : ID(rails generated), Title, Description, User_id
- Users Columns : ID(rails generated), username, email, admin(T/F) *article_categories Columns : article_id, category_id
- One-to Many relation with the user and articles.
- Many-to-Many relation between article and categories.
-
CRUD Operation : create, read, update, delete
-
Naming Convention:
- Model - Singular first letter Uppercase(Article)
- Tablename - Plural, lower case of model name(articles)
- Model name file - all lowercase but singular(article.rb)
- Controller_name - Plural of model(articles_controller.rb)
- To run server "rails s -b $IP -p $PORT"
- gems are ruby programs and libraries.
- bundle install is bundler gem which goes to ruby gems and install all the default gems.
- Routes are in routes.rb
- Helpers are common logic for views.
- database.yml for database configuration.
- seeds.rb for database migrations storage.
- All the logs from server output will be stored in logs.
- Public folder has html pages that are directly available.
- Automated tests happened in test directory.
- In vendor we have all installed gem files.
- README.md contains information which we want to expose about our application.
- By default web server is webrick.
- "rake routes" cmd is for checking what routes are available.
- action means method in controller class.
- for each action we need template in views.
- <% %> for writing ruby code inside template.
- <%= this is going to render what is evaluated.
- Rails use active record pattern to communicate with database.
- "rails generate scaffold Article title:string description:text" will create table named Article and corresponding controller and model routes and all other things which are required.
- "rails generate scaffold Model columns:type model:references" for creating a foreign key reference between models.
- "rails destroy scaffold Model" to destroy a model.
- "rake db:migrate" for migrating database by creating tables.
- "rake route | grep articles" to see all the routes for articles.
- "CRUD" operation comes inbuilt!!!
- "rails generate migration create_articles" to generate a migration.
- Model.create(args) for direct entry of values.
- "article.errors.any?" to check if there is any error with article entry.
- "article.errors.full_messages" to show the full message related to error.
- "application.html.erb" file wraps all the views.
- Partials are used to make code redundent "_form.html.erb"
- "heroku run rake db:migrate" for migrating databse with heroku.
- "has_many" should be added in the model which has one to many relation.
- Any change is instantly reflected in the Active Record objects. The mapping that binds a given Active Record class to a certain database table will happen automatically in most common cases, but can be overwritten for the uncommon ones.
- "rails generate migration add_user_id_to_articles" to create association between articles and users
- "byebug" gem is used for debugging.
- "has_secure_password" method in the model user.rb.
- "gem bcrypt" in the gemfile.
- password_digest attribute in the users table.
- One way hashed digest of a string is stored by password_digest.
- resource.authenticate('password') for comparing password.
- Methods that are crreated in application controller are available to all the controllers.Not available in views by default.
- setup method will start first whenever we start testing.
- "rake test" cmd to start all test cases.