新增:许可证排序字段

This commit is contained in:
yystopf 2024-08-09 11:22:45 +08:00
parent 6ba2d39e9b
commit bd9ca0439c
5 changed files with 24 additions and 3 deletions

View File

@ -7,7 +7,7 @@ class Admins::ProjectLicensesController < Admins::BaseController
sort_by = License.column_names.include?(params[:sort_by]) ? params[:sort_by] : 'created_at'
sort_direction = %w(desc asc).include?(params[:sort_direction]) ? params[:sort_direction] : 'desc'
q = License.ransack(name_cont: params[:search])
project_licenses = q.result(distinct: true).order("#{sort_by} #{sort_direction}")
project_licenses = q.result(distinct: true).reorder("#{sort_by} #{sort_direction}")
@project_licenses = paginate(project_licenses)
end
@ -96,7 +96,7 @@ class Admins::ProjectLicensesController < Admins::BaseController
end
def license_params
params.require(:license).permit(:name,:content)
params.require(:license).permit(:name,:content,:position)
end
# def validate_params

View File

@ -7,10 +7,12 @@
# content :text(65535)
# created_at :datetime not null
# updated_at :datetime not null
# is_secret :boolean default("0")
# position :integer default("0")
#
class License < ApplicationRecord
default_scope { order(position: :desc) }
include Projectable
validates :name, :content, presence: true

View File

@ -30,6 +30,18 @@
</div>
<div class="form-group">
<label>
<span class="color-grey-6 pt10">
排序等级
<span class="ml10 color-orange mr20">*</span>
</span>
</label>
<div class="mt-10">
<%= f.number_field :position, class: "form-control",placeholder: ""%>
</div>
</div>
<div class="form-group">
<%= f.submit "确认", class: "btn btn-primary submit-btn" %>

View File

@ -4,6 +4,7 @@
<th width="5%">序号</th>
<th width="15%">名称</th>
<th width="35%">简介</th>
<th width="10%"><%= sort_tag('排序等级', name: 'position', path: admins_project_licenses_path) %></th>
<%
=begin%>
<th width="10%"><%= sort_tag('项目数', name: 'projects_count', path: admins_project_licenses_path) %></th>
@ -24,6 +25,7 @@
<td>
<%= project_license.content.to_s.truncate(200) %>
</td>
<td><%= project_license.position %></td>
<%
=begin%>
<td><%= project_license.projects_count %></td>

View File

@ -0,0 +1,5 @@
class AddPositionToLicenses < ActiveRecord::Migration[5.2]
def change
add_column :licenses, :position, :integer, default: 0
end
end