SWorD (Social Web of real Domotics) is a prototype social network where users, homes, providers, devices and appliances can interact and act in a "smarter" way, by talking each other and thus lowering the technical knowledge to use home automation and domotics systems.
- Creation of static pages for our social network: home, about and contact
rails generate controller Pages home about contact
(or from the RubyMine menu Tools > Run Rails Generator...)
- Add title to HTML files: "SWorD | Page name"
- by using the
provide
method in each view, i.e.,<% provide :title, 'Page name' %>
- by editing the title tag in
app/views/layouts/application.html.erb
, i.e.,<title>SWorD | <%= yield(:title) %>
- learn more about
provide
at http://api.rubyonrails.org/classes/ActionView/Helpers/CaptureHelper.html#method-i-provide
- Add an helper to avoid wrong rendering if the page title is not declared
- in
app/helpers/application_helper.rb
- by editing the title tag in
app/views/layouts/application.html.erb
-
Fill with some contents all the views
-
Add
bootstrap-sass
gem to include the Bootstrap framework with Sass support http://twitter.github.io/bootstrap/
- update the
Gemfile
- run
bundle install
- Add and fill a custom SCSS file in
app/assets/stylesheets
-
Move HTML shim, header and footer code in three partials (placed in
app/views/layouts/
) -
Update the
routes.rb
file, according to the table present in the exercise 1 text -
Update links present in
_header.html.erb
and_footer.html.erb
-
Add a faq page:
- add a new view called
faq.html.erb
with a content similar to the other views - update the Pages controller
- add the corresponding named route to
routes.rb
- Add a Users controller and a page named "new"
rails generate controller Users new
(or from the RubyMine menu Tools > Run Rails Generator...)- fill the content of the
new.html.erb
view - update/add the corresponding named route to
routes.rb
, mapping it with the signup URI - update the "Sign Up" link present in
home.html.erb
- Generate the User model, with two attributes: name and email
rails generate model User name:string email:string
(or from the RubyMine menu Tools > Run Rails Generator...)
- Migrate the model to the database (i.e., create the table and columns corresponding to the User model)
bundle exec rake db:migrate
(or from the RubyMine menu Tools > Run Rake Tasks...)
- Add some gems to the Gemfile (and perform a
bundle install
)
annotate
(version 2.5.0) to show some annotations in the Rails modelsbcrypt-ruby
(already present, but commented) to have some state-of-the-art hash functions available in Rails
- Annotate the User model to show a little bit more information
bundle exec annotate
(or add a new configuration of type Gem Command from the RubyMine menu Run > Edit Configurations...)
-
Add debug information in
application.html.erb
, by using thedebug
method -
Add some validations to the User model
name
must be always present (presence: true
) and it must have a maximum length of 50 characters (length: { maximum: 50 }
)email
must be always present, unique (uniqueness: { case_sensitive: false }
) and with a specific defined format (format: { with: VALID_EMAIL_REGEX }
)
- Enforce the uniqueness of the email by using a migration
- add an index on the
email
column in the database
- Give to the User model a
password
field
- generate/migrate a migration to add a column to store the password digest (i.e., an encrypted version of the password)
- update the User model with two virtual attributes:
password
andpassword_confirmation
- add the
has_secure_password
method to the User model, to use the authentication system of Rails
- Add routes for users
resources :users
inconfig/routes.rb
-
Add a user in the database, by editing the action
new
in the Users controller -
Add a new view associated to the Users controller
- create
show.html.erb
inapp/views/users
(filled with some contents) - update the page stylesheet
- add the corresponding action to the User controller (
users_controller.rb
)
- Add an helper for using a Gravatar as profile pic for the users (in
users_helper.rb
)
- update the view responsible of showing users (
show.html.erb
)