From e024839cb67346607696992802f65e25ca81b1ac Mon Sep 17 00:00:00 2001 From: Dan Elbert Date: Thu, 21 Jan 2016 11:45:46 -0600 Subject: [PATCH] Fixed small items --- app/assets/stylesheets/recipes.scss | 6 ++++++ app/controllers/users_controller.rb | 4 ++-- app/models/recipe_ingredient.rb | 12 ++++++++++++ app/models/user.rb | 4 ++-- app/views/recipes/show.html.erb | 4 ++-- app/views/users/login.html.erb | 4 ++-- 6 files changed, 26 insertions(+), 8 deletions(-) diff --git a/app/assets/stylesheets/recipes.scss b/app/assets/stylesheets/recipes.scss index 7aced8c..5c205fb 100644 --- a/app/assets/stylesheets/recipes.scss +++ b/app/assets/stylesheets/recipes.scss @@ -51,6 +51,12 @@ div#ingredient-list, div#step-list { } div.recipe-view { + + .source { + @extend .col-xs-6; + word-wrap: break-word; + } + .ingredients div { padding-bottom: 15px; } diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 6b3e614..e6bf808 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -14,9 +14,9 @@ class UsersController < ApplicationController end def verify_login - if user = User.authenticate(params[:email], params[:password]) + if user = User.authenticate(params[:username], params[:password]) set_current_user(user) - flash[:notice] = "Welcome, #{user.full_name}" + flash[:notice] = "Welcome, #{user.display_name}" redirect_to root_path else flash[:error] = "Invalid credentials" diff --git a/app/models/recipe_ingredient.rb b/app/models/recipe_ingredient.rb index 26290be..b24ef2e 100644 --- a/app/models/recipe_ingredient.rb +++ b/app/models/recipe_ingredient.rb @@ -22,6 +22,18 @@ class RecipeIngredient < ActiveRecord::Base end end + def display_name + if quantity.present? && units.present? + "#{quantity} #{units} of #{custom_name}" + elsif quantity.present? + "#{quantity} #{custom_name}" + elsif units.present? + "#{units} #{custom_name}" + else + custom_name + end + end + def scale(factor, auto_unit = false) if factor.present? && self.quantity.present? && factor != '1' self.quantity = UnitConversion.convert(self.quantity, factor, nil, nil) diff --git a/app/models/user.rb b/app/models/user.rb index 2df7250..265a353 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -4,8 +4,8 @@ class User < ActiveRecord::Base validates :username, presence: true, uniqueness: { case_sensitive: false } - def self.authenticate(email, password) - find_by_email(email).try(:authenticate, password) + def self.authenticate(username, password) + find_by_username(username).try(:authenticate, password) end def display_name diff --git a/app/views/recipes/show.html.erb b/app/views/recipes/show.html.erb index e1bf423..1bb88c2 100644 --- a/app/views/recipes/show.html.erb +++ b/app/views/recipes/show.html.erb @@ -44,7 +44,7 @@ <% end %> <% if @recipe.source.present? %> -
+

Source

<%= @recipe.source %>

<% end %> @@ -60,7 +60,7 @@
    <% @recipe.recipe_ingredients.each do |i| %> -
  • <%= "#{i.quantity} #{i.units} of #{i.custom_name}" %>
  • +
  • <%= i.display_name %>
  • <% end %>
diff --git a/app/views/users/login.html.erb b/app/views/users/login.html.erb index 5ed4e1d..2fc37ad 100644 --- a/app/views/users/login.html.erb +++ b/app/views/users/login.html.erb @@ -11,8 +11,8 @@ <%= form_tag(login_path, :method => :post) do %>
- <%= label_tag :email, "Email", class: 'control-label' %> - <%= text_field_tag :email, nil, class: 'form-control' %> + <%= label_tag :username, "Username", class: 'control-label' %> + <%= text_field_tag :username, nil, class: 'form-control' %>