From dc702a89811e866eec20cc43763096dddf4a41fe Mon Sep 17 00:00:00 2001 From: mo Date: Sun, 24 Sep 2017 13:27:31 -0600 Subject: extract my cakes controller. --- app/controllers/my/cakes_controller.rb | 7 +++++++ app/controllers/my/dashboard_controller.rb | 2 +- app/views/cakes/_cake.html.erb | 5 +++++ app/views/layouts/_header.html.erb | 2 +- app/views/my/cakes/index.html.erb | 17 +++++++++++++++++ app/views/my/dashboard/_creation.html.erb | 13 ------------- app/views/my/dashboard/index.html.erb | 17 +++++++++-------- config/routes.rb | 1 + 8 files changed, 41 insertions(+), 23 deletions(-) create mode 100644 app/controllers/my/cakes_controller.rb create mode 100644 app/views/my/cakes/index.html.erb delete mode 100644 app/views/my/dashboard/_creation.html.erb diff --git a/app/controllers/my/cakes_controller.rb b/app/controllers/my/cakes_controller.rb new file mode 100644 index 00000000..bfc85dc7 --- /dev/null +++ b/app/controllers/my/cakes_controller.rb @@ -0,0 +1,7 @@ +module My + class CakesController < BaseController + def index + @cakes = current_user.creations.includes(:photos) + end + end +end diff --git a/app/controllers/my/dashboard_controller.rb b/app/controllers/my/dashboard_controller.rb index 158dc91c..c3e551bc 100644 --- a/app/controllers/my/dashboard_controller.rb +++ b/app/controllers/my/dashboard_controller.rb @@ -1,7 +1,7 @@ module My class DashboardController < BaseController def index - @cakes = current_user.creations.includes(:photos) + @cakes = current_user.creations.includes(:photos).limit(6) @tutorials = current_user.tutorials.limit(10) @activities = current_user.recent_activities end diff --git a/app/views/cakes/_cake.html.erb b/app/views/cakes/_cake.html.erb index edfd983b..f7666d00 100644 --- a/app/views/cakes/_cake.html.erb +++ b/app/views/cakes/_cake.html.erb @@ -5,5 +5,10 @@

<%= cake.name %>

<%= local_time(cake.created_at) %>

+ <% if current_user && current_user.id == cake.user_id %> + <%= link_to my_root_path(anchor: "cakes/#{cake.id}/edit"), class: 'card-link' do %> + edit + <% end %> + <% end %>
diff --git a/app/views/layouts/_header.html.erb b/app/views/layouts/_header.html.erb index 0e1b403c..9fd798a0 100644 --- a/app/views/layouts/_header.html.erb +++ b/app/views/layouts/_header.html.erb @@ -20,7 +20,7 @@ <%= link_to my_dashboard_path, id: 'navbarDropdownMenuLink', class: 'nav-link dropdown-toggle', data: { toggle: 'dropdown' }, 'aria-haspopup'=>"true", 'aria-expanded'=>"false" do %> <%= current_user.name %> <% end %> -