Skip to content

Commit

Permalink
rubocop auto correct
Browse files Browse the repository at this point in the history
  • Loading branch information
masahiko kawai committed Jun 4, 2019
1 parent 569af83 commit e7afbe7
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 24 deletions.
24 changes: 12 additions & 12 deletions app/controllers/tasks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ class TasksController < ApplicationController
before_action :set_task, only: %i[show edit update destroy]

def index
if params[:commit].nil?
@tasks = Task.all.page(params[:page])
else
@tasks = Task.name_like(params[:name]).
status(params[:status]).
page(params[:page])
end
@tasks = if params[:commit].nil?
Task.all.page(params[:page])
else
Task.name_like(params[:name]).
status(params[:status]).
page(params[:page])
end

if params[:sort].present?
@tasks = @tasks.order(created_at: params[:sort])
else
@tasks = @tasks.order(created_at: :desc)
end
@tasks = if params[:sort].present?
@tasks.order(created_at: params[:sort])
else
@tasks.order(created_at: :desc)
end
end

def new
Expand Down
4 changes: 2 additions & 2 deletions app/models/task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ class Task < ApplicationRecord

validates :name, presence: true, length: { maximum: 20 }

scope :name_like, -> name { where('name like ?', "%#{name}%") if name.present? }
scope :status, -> status { where(status: status) if status.present? }
scope :name_like, -> (name) { where('name like ?', "%#{name}%") if name.present? }
scope :status, -> (status) { where(status: status) if status.present? }
end
1 change: 1 addition & 0 deletions config/initializers/kaminari_config.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

Kaminari.configure do |config|
config.default_per_page = 10
# config.max_per_page = nil
Expand Down
2 changes: 2 additions & 0 deletions db/migrate/20190604050732_add_index_to_task.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class AddIndexToTask < ActiveRecord::Migration[5.2]
def change
add_index :tasks, :status
Expand Down
20 changes: 10 additions & 10 deletions db/schema.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
Expand All @@ -10,15 +12,13 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2019_06_04_050732) do

create_table "tasks", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
t.string "name", limit: 20, null: false
t.text "description"
t.integer "status", limit: 1, default: 1, null: false, unsigned: true
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["status"], name: "index_tasks_on_status"
ActiveRecord::Schema.define(version: 20_190_604_050_732) do
create_table 'tasks', options: 'ENGINE=InnoDB DEFAULT CHARSET=utf8', force: :cascade do |t|
t.string 'name', limit: 20, null: false
t.text 'description'
t.integer 'status', limit: 1, default: 1, null: false, unsigned: true
t.datetime 'created_at', null: false
t.datetime 'updated_at', null: false
t.index ['status'], name: 'index_tasks_on_status'
end

end

0 comments on commit e7afbe7

Please sign in to comment.