Rails Portfolio Project – Recipe Manager

Recipe Manager was built using Ruby on Rails framework and Bootstrap. All users can safely signup, login and logout. I created authentication and authorization methods without using any gem. Recipe Manager include a third party signup/login via Github thanks to the OmniAuth gem.

Users can check the recipes, rate and comment them but only admin users can create and edit the recipes and the categories. The user can browse recipes by name and author and all the comments by author and recipe. The app include reasonable validations for its forms and an ActiveRecord scope method to get the newest recipe that can be seen in its own URL, in this case: http://localhost:3000/newest_recipe.

My models:

User

  • Has many recipes
  • Has many comments
  • Has many ratings
  • Attributes: name, email, password_digest, admin, and finally I added uid and provider for the signup/login with OmniAuth.

Recipe:

  • Belongs to a user
  • Has many recipe_ingredients
  • Has many ingredients through recipe_ingredients
  • Has many recipe_categories
  • Has many categories through recipe_categories
  • Has many comments
  • Has many ratings
  • Attributes: name, cooking_time, servings, directions, date created

Ingredient

  • Has many recipe_ingredients
  • Has many recipes through recipe_ingredients
  • Attributes: name

RecipeIngredient

  • Belongs to recipe
  • Belongs to ingredient
  • Attributes: quantity.

Category

  • Has many recipe_categories
  • Has many recipes through recipe_categories
  • Attributes: name

RecipeCategory

  • Belongs to Recipe
  • Belongs to Category

Comment

  • Belongs to user
  • Belongs to recipe
  • Attributes: content

Rating

  • Belongs to user
  • Belongs to recipe
  • Attributes: score

Generate my new application:

Generate my models with their associations and create my db:

*Adding :default => true to boolean in existing Rails column

Implementing a sign-in, login and logout functionality:

In order to encrypt the passwords I will use the gem bcrypt, include “has_secure_password” in my User model and have a password_digest attribute in my users table.

Sign in with Github

  • Add to your gemfile the OmniAuth gem and the provider-specific OmniAuth gem, in this case “omniauth-github”, and run bundle install.
  • Create a file named config/initializers/omniauth.rb. I will contain the following:
  • Create an application in Github.

[Settings/Developer Settings/OAuth Apps/Register a new OAuth application]

In homepage url enter: https://localhost:3000/

In the Authorization url: http://localhost:3000/auth/github/callback

After creating the app you get a client ID and a Client secret.

  • Add dotenv-rails to your Gemfile and run bundle install.
  • Create a file named .env at the root of the application and add your Github credentials.

  • Add .env to your .gitignore file.
  • Create a link to login via Github
  • The User model needs these attributes, all strings: name, email and uid, that it is the user’s ID on Github. *I added a provider attribute later on.
  • Create the route where Github will redirect users in the callback phase of the login process.
  • And in our Sessions controller we find or create the user who logging via github.
  • In our User model:

I want to add some helpful links: