diff options
| author | mo <mo.khan@gmail.com> | 2017-09-24 13:27:31 -0600 |
|---|---|---|
| committer | mo <mo.khan@gmail.com> | 2017-09-24 13:27:31 -0600 |
| commit | dc702a89811e866eec20cc43763096dddf4a41fe (patch) | |
| tree | 40a8e9bc97dedefec9b82331ce499d8189da7dc9 | |
| parent | 5395834ccb947dd90e6412e2b27d9e9f120e1ce2 (diff) | |
extract my cakes controller.
| -rw-r--r-- | app/controllers/my/cakes_controller.rb | 7 | ||||
| -rw-r--r-- | app/controllers/my/dashboard_controller.rb | 2 | ||||
| -rw-r--r-- | app/views/cakes/_cake.html.erb | 5 | ||||
| -rw-r--r-- | app/views/layouts/_header.html.erb | 2 | ||||
| -rw-r--r-- | app/views/my/cakes/index.html.erb | 17 | ||||
| -rw-r--r-- | app/views/my/dashboard/_creation.html.erb | 13 | ||||
| -rw-r--r-- | app/views/my/dashboard/index.html.erb | 17 | ||||
| -rw-r--r-- | config/routes.rb | 1 |
8 files changed, 41 insertions, 23 deletions
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 @@ <div class="card-body"> <h4 class="card-title"><%= cake.name %></h4> <p class="card-text"><small class="text-muted"><%= local_time(cake.created_at) %></small></p> + <% if current_user && current_user.id == cake.user_id %> + <%= link_to my_root_path(anchor: "cakes/#{cake.id}/edit"), class: 'card-link' do %> + <i class="fa fa-pencil-square-o"></i> edit + <% end %> + <% end %> </div> </div> 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 %> - <div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink" data-no-turbolink> + <div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink"> <%= link_to my_root_path(anchor: 'cakes/new'), class: 'dropdown-item' do %> <i class="fa fa-upload"></i> New Cake <% end %> diff --git a/app/views/my/cakes/index.html.erb b/app/views/my/cakes/index.html.erb new file mode 100644 index 00000000..68f6fc0e --- /dev/null +++ b/app/views/my/cakes/index.html.erb @@ -0,0 +1,17 @@ +<% provide(:title, "My Cakes") -%> + +<div class="row"> + <div class="col-3"> + <%= render partial: "my/shared/my_nav" %> + </div> + <div class="col-9"> + <div class="row"> + <div class="col"> + <h5>My Cakes</h5> + <div class="card-columns"> + <%= render partial: 'cakes/cake', collection: @cakes, cached: true %> + </div> + </div> + </div> + </div> +</div> diff --git a/app/views/my/dashboard/_creation.html.erb b/app/views/my/dashboard/_creation.html.erb deleted file mode 100644 index 69d65e00..00000000 --- a/app/views/my/dashboard/_creation.html.erb +++ /dev/null @@ -1,13 +0,0 @@ -<div class="media"> - <%= link_to my_root_path(anchor: "cakes/#{item.id}") do %> - <%= image_tag item.primary_image.url_for(:thumb), class: 'd-flex mr-3', width: '64px' %> - <% end %> - <div class="media-body"> - <h5 class="mt-0 mb-1"><%= item.name %></h5> - <p> - <%= link_to my_root_path(anchor: "cakes/#{item.id}/edit") do %> - <i class="fa fa-pencil-square-o"></i> edit - <% end %> - </p> - </div> -</div> diff --git a/app/views/my/dashboard/index.html.erb b/app/views/my/dashboard/index.html.erb index e16eef03..5ec39659 100644 --- a/app/views/my/dashboard/index.html.erb +++ b/app/views/my/dashboard/index.html.erb @@ -3,16 +3,16 @@ <div class="col-3"> <%= render partial: "my/shared/my_nav" %> </div> - <div class="col-9" data-no-turbolink> + <div class="col-9"> <div class="row"> <div class="col"> - <h5>My Cakes</h5> - <ul class="list-unstyled"> - <% @cakes.each do |item| %> - <%= render item.class.to_s.downcase, item: item %> - <% end %> - </ul> + <h5><%= link_to "My Cakes", my_cakes_path %></h5> + <div class="card-columns"> + <%= render partial: 'cakes/cake', collection: @cakes, cached: true %> + </div> </div> + </div> + <div class="row"> <div class="col"> <div class="well"> <h5>My Notifications</h5> @@ -24,7 +24,8 @@ <% end %> <% end %> </div> - + </div> + <div class="col"> <% if @tutorials.any? %> <h5>My Tutorials</h5> <ol> diff --git a/config/routes.rb b/config/routes.rb index 381d2410..152dce8a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -86,6 +86,7 @@ Cake::Application.routes.draw do namespace :my do get 'dashboard', to: 'dashboard#index' + resources :cakes, only: [:index] resources :favorites, only: [:index] resources :settings, only: [:index, :update] resources :passwords, only: [:index, :update] |
