Skip to content

Commit

Permalink
Merge pull request #19 from VuongGiang/comic_category
Browse files Browse the repository at this point in the history
create comic_category
  • Loading branch information
chintk authored Aug 27, 2018
2 parents 2c64c98 + b378da9 commit c4620ef
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 30 deletions.
7 changes: 6 additions & 1 deletion app/assets/stylesheets/custom.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ $gray-medium-light: #eaeaea;
.navbar {
background-image: url("bg6.jpg");
height: 110px;
padding-top: 20px;
margin-top: -70px;
padding-top: 10px;
}
footer {
padding-top: 20px;
Expand Down Expand Up @@ -150,3 +151,7 @@ input {
width: auto;
margin-left: 0;
}
.row {
width: 1000px;
margin: 0 auto;
}
12 changes: 4 additions & 8 deletions app/controllers/comics_controller.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
class ComicsController < ApplicationController
def index
@comics = if params[:category]
Category.find(params[:category]).comics
else
Comic.all
end
@comic = Comic.new
@author = @comic.author
@category = Category.find_by_id params[:category_id]
@comics = @category&.comics || Comic.all
end

def new
Expand All @@ -16,6 +11,7 @@ def new
def show
@comic = Comic.find params[:id]
@author = @comic.author
@category = @comic.category_ids
end

def create
Expand Down Expand Up @@ -52,6 +48,6 @@ def destroy

private
def comic_params
params.require(:comic).permit :title, :content, :author_id, :picture
params.require(:comic).permit :title, :content, :author_id, :picture, category_ids: []
end
end
17 changes: 12 additions & 5 deletions app/views/comics/_comic.html.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
<li id='comic-<%= comic.id %>'>
<div class='user'><%= link_to comic.user.name, comic.user %></div>
<div class='title'><%= link_to comic.title, comic %></div>
<div class='content-comic'><%= comic.content %></div>
<div class='author'><%= link_to comic.author.name, comic.author %></div>
<div class='picture'> <%= image_tag comic.picture.url if comic.picture? %></div>
<div class='title'>
<%= link_to comic.title, comic %>
</div>
<div class='content-comic'>
<%= comic.content %>
</div>
<div class='author'>
<%= link_to comic.author.name, comic.author %>
</div>
<div class='picture'>
<%= image_tag comic.picture.url if comic.picture? %>
</div>
<%= link_to t('.delete'), comic, method: :delete, data: { confirm: t('.sure') } %> |
<%= link_to t('.edit'), edit_comic_path(comic) %>
</li>
5 changes: 1 addition & 4 deletions app/views/comics/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
<% provide :title, t('.comics') %>

<h1><%= t '.comics' %></h1>
<h1><%= @category&.name || t('.comics') %></h1>
<ul>
<%= render @comics %>
</ul>
<div class='comic_form'>
<%= render 'shared/comic_form' %>
</div>
37 changes: 30 additions & 7 deletions app/views/comics/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,34 @@
<h1><%= @comic.title %></h1>

<li id='comic-<%= @comic.id %>'>
<div class='user'><%= link_to @comic.user.name, @comic.user %></div>
<div class='title'><%= @comic.title %></div>
<div class='content-comic'><%= @comic.content %></div>
<div class='author'><%= link_to @comic.author.name, @comic.author %></div>
<%= link_to t('.delete'), @comic, method: :delete, data: { confirm: t('.sure') } %> |
<%= link_to t('.edit'), edit_comic_path(@comic) %>
<%= render 'shared/comic_stats' %>
<div class='row'>
<div class='col col-md-6'>
<div class='picture-show'>
<%= image_tag @comic.picture.url if @comic.picture? %>
</div>
</div>
<div class='col col-md-6'>
<div class='title'>
<%= t '.title' %>
<%= @comic.title %>
</div>
<div class='content-comic'>
<%= t '.intro' %>
<%= @comic.content %>
</div>
<div class='author'>
<%= t '.author' %>
<%= link_to @comic.author.name, @comic.author %>
</div>
<div class='category'>
<%= t '.category' %>
<% @comic.categories.each do |category| %>
<%= link_to category.name, category %> |
<% end %>
</div>
<%= link_to t('.delete'), @comic, method: :delete, data: { confirm: t('.sure') } %> |
<%= link_to t('.edit'), edit_comic_path(@comic) %>
<%= render 'shared/comic_stats' %>
</div>
</div>
</li>
8 changes: 4 additions & 4 deletions app/views/layouts/_header.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<div class='container'>
<nav>
<ul>
<form class='search form-inline my-2 my-lg-0'>
<input class='form-control mr-sm-2' type='search' placeholder='Search' aria-label='Search'>
<button class='btn btn-outline-success my-2 my-sm-0' type='submit'><%= link_to t('.search'), '#' %></button>
<form class="form-inline md-form form-sm">
<i class="fa fa-search" aria-hidden="true"></i>
<input class="form-control form-control-sm ml-3 w-75" type="text" placeholder="Search" aria-label="Search">
</form>
</ul>
<ul class='nav navbar-nav navbar-left'>
Expand All @@ -14,7 +14,7 @@
<a class='nav-link dropdown-toggle' href='#' id='navbarDropdown' role='button' data-toggle='dropdown' aria-haspopup='true' aria-expanded='false'><%= t('.category') %></a>
<div class='dropdown-menu' aria-labelledby='navbarDropdown'>
<% Category.all.each do |category| %>
<%= link_to category.name, comics_path(category: category), class: 'dropdown-item' %>
<%= link_to category.name, category_comics_path(category), class: 'dropdown-item' %>
<% end %>
</div>
</li>
Expand Down
9 changes: 9 additions & 0 deletions app/views/shared/_comic_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@
<div class='field'>
<%= f.select :author_id, options_from_collection_for_select(Author.all, :id, :name) %>
</div>
<div class="field">
<%= f.label "Select Categories" %><br />
<%= f.collection_check_boxes :category_ids, Category.all, :id, :name do |b| %>
<div class="collection-check-box">
<%= b.check_box %>
<%= b.label %>
</div>
<% end %>
</div>
<span class="picture">
<%= f.file_field :picture, accept: 'image/jpeg,image/gif,image/png' %>
</span>
Expand Down
4 changes: 4 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ en:
edit: 'edit'
delete: 'delete'
sure: 'You sure?'
title: 'Title:'
intro: 'Introduce:'
author: 'Author:'
category: 'Category:'
follow:
follow: 'Follow'
unfollow:
Expand Down
4 changes: 3 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
get '/login', to: 'sessions#new'
post '/login', to: 'sessions#create'
delete '/logout', to: 'sessions#destroy'
resources :categories
resources :categories do
resources :comics
end
resources :users do
resources :follows, only: [:create, :destroy, :index]
end
Expand Down
Binary file modified db/development.sqlite3
Binary file not shown.

0 comments on commit c4620ef

Please sign in to comment.