diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index c3b0f23..5c6a2aa 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -4,7 +4,7 @@ class ApplicationController < ActionController::Base protect_from_forgery with: :exception def ensure_valid_user - if current_user.nil? + unless current_user? flash[:warning] = "You must login" redirect_to login_path end @@ -22,6 +22,11 @@ class ApplicationController < ActionController::Base end helper_method :current_user + def current_user? + !current_user.nil? + end + helper_method :current_user? + def set_current_user(user) if user session[:user_id] = user.id diff --git a/app/views/recipes/index.html.erb b/app/views/recipes/index.html.erb index f6238a7..edb43d4 100644 --- a/app/views/recipes/index.html.erb +++ b/app/views/recipes/index.html.erb @@ -14,7 +14,9 @@ Name - + <% if current_user? %> + + <% end %> Yields Time Created @@ -26,16 +28,20 @@ <% @recipes.each do |recipe| %> <%= link_to recipe.display_name, recipe %> - - <%= link_to edit_recipe_path(recipe), class: 'btn btn-sm btn-primary' do %> - - <% end %> - - - <%= link_to recipe, method: :delete, data: { confirm: 'Are you sure?' }, class: 'btn btn-sm btn-danger' do %> - - <% end %> - + + <% if current_user? %> + + <%= link_to edit_recipe_path(recipe), class: 'btn btn-sm btn-primary' do %> + + <% end %> + + + <%= link_to recipe, method: :delete, data: { confirm: 'Are you sure?' }, class: 'btn btn-sm btn-danger' do %> + + <% end %> + + <% end %> + <%= recipe.yields %> <%= recipe_time(recipe) %> <%= timestamp(recipe.created_at) %>