From b378da96d7a23273ac620e1bb5f4cc8ce34725de Mon Sep 17 00:00:00 2001 From: Vuong Giang Date: Fri, 24 Aug 2018 21:04:25 +0700 Subject: [PATCH] create comic_category --- app/assets/stylesheets/custom.scss | 7 ++++- app/controllers/comics_controller.rb | 12 +++------ app/views/comics/_comic.html.erb | 17 ++++++++---- app/views/comics/index.html.erb | 5 +--- app/views/comics/show.html.erb | 37 +++++++++++++++++++++----- app/views/layouts/_header.html.erb | 8 +++--- app/views/shared/_comic_form.html.erb | 9 +++++++ config/locales/en.yml | 4 +++ config/routes.rb | 4 ++- db/development.sqlite3 | Bin 34816 -> 35840 bytes 10 files changed, 73 insertions(+), 30 deletions(-) diff --git a/app/assets/stylesheets/custom.scss b/app/assets/stylesheets/custom.scss index fe16ea1..80f518e 100644 --- a/app/assets/stylesheets/custom.scss +++ b/app/assets/stylesheets/custom.scss @@ -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; @@ -150,3 +151,7 @@ input { width: auto; margin-left: 0; } +.row { + width: 1000px; + margin: 0 auto; +} diff --git a/app/controllers/comics_controller.rb b/app/controllers/comics_controller.rb index ad76b41..f85b483 100644 --- a/app/controllers/comics_controller.rb +++ b/app/controllers/comics_controller.rb @@ -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 @@ -16,6 +11,7 @@ def new def show @comic = Comic.find params[:id] @author = @comic.author + @category = @comic.category_ids end def create @@ -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 diff --git a/app/views/comics/_comic.html.erb b/app/views/comics/_comic.html.erb index 26b193d..971a41c 100644 --- a/app/views/comics/_comic.html.erb +++ b/app/views/comics/_comic.html.erb @@ -1,9 +1,16 @@
  • -
    <%= link_to comic.user.name, comic.user %>
    -
    <%= link_to comic.title, comic %>
    -
    <%= comic.content %>
    -
    <%= link_to comic.author.name, comic.author %>
    -
    <%= image_tag comic.picture.url if comic.picture? %>
    +
    + <%= link_to comic.title, comic %> +
    +
    + <%= comic.content %> +
    +
    + <%= link_to comic.author.name, comic.author %> +
    +
    + <%= image_tag comic.picture.url if comic.picture? %> +
    <%= link_to t('.delete'), comic, method: :delete, data: { confirm: t('.sure') } %> | <%= link_to t('.edit'), edit_comic_path(comic) %>
  • diff --git a/app/views/comics/index.html.erb b/app/views/comics/index.html.erb index e83453e..e908bc8 100644 --- a/app/views/comics/index.html.erb +++ b/app/views/comics/index.html.erb @@ -1,9 +1,6 @@ <% provide :title, t('.comics') %> -

    <%= t '.comics' %>

    +

    <%= @category&.name || t('.comics') %>

    -
    - <%= render 'shared/comic_form' %> -
    diff --git a/app/views/comics/show.html.erb b/app/views/comics/show.html.erb index 3b13cea..c5b6499 100644 --- a/app/views/comics/show.html.erb +++ b/app/views/comics/show.html.erb @@ -2,11 +2,34 @@

    <%= @comic.title %>

  • -
    <%= link_to @comic.user.name, @comic.user %>
    -
    <%= @comic.title %>
    -
    <%= @comic.content %>
    -
    <%= link_to @comic.author.name, @comic.author %>
    - <%= link_to t('.delete'), @comic, method: :delete, data: { confirm: t('.sure') } %> | - <%= link_to t('.edit'), edit_comic_path(@comic) %> - <%= render 'shared/comic_stats' %> +
    +
    +
    + <%= image_tag @comic.picture.url if @comic.picture? %> +
    +
    +
    +
    + <%= t '.title' %> + <%= @comic.title %> +
    +
    + <%= t '.intro' %> + <%= @comic.content %> +
    +
    + <%= t '.author' %> + <%= link_to @comic.author.name, @comic.author %> +
    +
    + <%= t '.category' %> + <% @comic.categories.each do |category| %> + <%= link_to category.name, category %> | + <% end %> +
    + <%= link_to t('.delete'), @comic, method: :delete, data: { confirm: t('.sure') } %> | + <%= link_to t('.edit'), edit_comic_path(@comic) %> + <%= render 'shared/comic_stats' %> +
    +
  • diff --git a/app/views/layouts/_header.html.erb b/app/views/layouts/_header.html.erb index ed4c4c4..a2c2772 100644 --- a/app/views/layouts/_header.html.erb +++ b/app/views/layouts/_header.html.erb @@ -2,9 +2,9 @@