У меня есть частичное в моем navbar
:
app/views/shared/_navbar.html.erb
<%= render :partial => 'shared/navbar/categories', collection: Category.root, :as => :category, locals: { f: f }, cached: true %>
app/views/shared/navbar/_categories.html.erb
<ul class="filter-parent">
<%= f.input :categories, collection: [category.name], as: :check_boxes %>
<li>
<%= render :partial => 'shared/navbar/categories', collection: category.children, :as => :category, locals: { f: f }, cached: true %>
</li>
</ul>
В моем category.rb
, я иметь следующее:
has_and_belongs_to_many :programs,
after_add: :touch_updated_at,
after_remove: :touch_updated_at
private
def touch_updated_at(program)
self.touch if persisted?
end
В моем program.rb
, у меня то же самое:
has_and_belongs_to_many :categories,
after_add: :touch_updated_at,
after_remove: :touch_updated_at
private
def touch_updated_at(category)
self.touch if persisted?
end
Однако в производственной (или когда в разработке включено кэширование), всякий раз, когда я создаю новая категория, затем добавьте к ней объект, она не показывает эту новую категорию в моей навигационной панели.
Вот записи именно этого.
Это создание новой category
от моего администратора.
Started POST "/admin/categories" for ::1 at 2020-02-26 00:31:48 -0500
Processing by Admin::CategoriesController#create as HTML
Parameters: {"authenticity_token"=>"G9wiRLElB5D9Bo6kw==", "category"=>{"program_ids"=>[""], "line_item_ids"=>[""], "order_line_item_ids"=>[""], "parent_category_id"=>"17", "child_ids"=>[""], "name"=>"Retro G", "status"=>"", "slug"=>"retro-g"}, "commit"=>"Create Category"}
User Load (3.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT $2 [["id", 1], ["LIMIT", 1]]
↳ app/controllers/admin/application_controller.rb:12:in `authenticate_admin'
Program Load (2.6ms) SELECT "programs".* FROM "programs" WHERE 1=0
LineItem Load (1.2ms) SELECT "line_items".* FROM "line_items" WHERE 1=0
OrderLineItem Load (1.5ms) SELECT "order_line_items".* FROM "order_line_items" WHERE 1=0
Category Load (1.2ms) SELECT "categories".* FROM "categories" WHERE 1=0
(2.1ms) BEGIN
Category Create (3.5ms) INSERT INTO "categories" ("parent_category_id", "name", "created_at", "updated_at", "slug") VALUES ($1, $2, $3, $4, $5) RETURNING "id" [["parent_category_id", 17], ["name", "Retro G"], ["created_at", "2020-02-26 05:31:48.920959"], ["updated_at", "2020-02-26 05:31:48.920959"], ["slug", "retro-g"]]
(2.6ms) COMMIT
Redirected to http://localhost:3000/admin/categories/retro-g
Completed 302 Found in 45ms (ActiveRecord: 17.7ms | Allocations: 12066)
Это присвоение подходящего program
этому category
.
Started PATCH "/admin/programs/billabong-pipe-masters" for ::1 at 2020-02-26 00:33:20 -0500
Processing by Admin::ProgramsController#update as HTML
Parameters: {"authenticity_token"=>"NNh6Frni5yNAg==", "program"=>{"name"=>"Billabong", "airs_at"=>"2020-12-08 00:00:00", "time_zone"=>"UTC", "published"=>"1", "available_vod"=>"1", "available_live"=>"1"}
User Load (2.8ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT $2 [["id", 1], ["LIMIT", 1]]
Program::HABTM_Categories Create (2.2ms) INSERT INTO "categories_programs" ("category_id", "program_id") VALUES ($1, $2) [["category_id", 36], ["program_id", 4290]]
Program Update (1.7ms) UPDATE "programs" SET "updated_at" = $1 WHERE "programs"."id" = $2 [["updated_at", "2020-02-26 05:33:20.937887"], ["id", 4290]]
↳ app/models/program.rb:246:in `touch_updated_at'
(3.0ms) COMMIT
Redirected to http://localhost:3000/admin/programs/billabong
Completed 302 Found in 199ms (ActiveRecord: 95.0ms | Allocations: 46916)
Я сократил его для краткости.
Что может быть причиной этого?