Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 3 Rails:缓存清理器和过期片段_Ruby On Rails 3_Fragment Caching_Sweeper - Fatal编程技术网

Ruby on rails 3 Rails:缓存清理器和过期片段

Ruby on rails 3 Rails:缓存清理器和过期片段,ruby-on-rails-3,fragment-caching,sweeper,Ruby On Rails 3,Fragment Caching,Sweeper,我有一个管理员可以创建新用户的表单,在这个表单中有一个remote:true。成功创建用户后,页面上显示所有用户的部分将更新。这不会发生在生产中,因为我已打开缓存 create.js.erb: <% if @user.valid? %> <% type = (@user.type == "Athlete" ? "athletes" : "high_school_coaches" ) %> alert("<%= @user.email %>

我有一个管理员可以创建新用户的表单,在这个表单中有一个
remote:true
。成功创建用户后,页面上显示所有用户的部分将更新。这不会发生在生产中,因为我已打开缓存

create.js.erb:

<% if @user.valid? %>
    <% type = (@user.type == "Athlete" ? "athletes" : "high_school_coaches" ) %> 
      alert("<%= @user.email %> created!");
      $('form#new_user').find('input:not(:hidden, :submit)').val('');
      $('.<%= type %>-container').html("<%= j render \"school_admin/#{type}/all\", users: @users.in_groups_of(3, false) %>")
<% else %>
  alert("<%= @user.errors.full_messages.to_sentence %>");
<% end %>
还有人遇到过这个问题吗?

解决了

忘记将此添加到我的控制器:

cache\u-sweeper:user\u-sweeper,仅限:[:创建]

class UserSweeper < ActionController::Caching::Sweeper
  observe Athlete, HighSchoolCoach

  def after_create(record)
    expire_cache(record)
  end

  def after_update(record)
    expire_cache(record)
  end

  def expire_cache(record)
    type = record.is_a?(HighSchoolCoach) ? "coach" : "athlete"
    expire_fragment("all_school_admin_#{type.pluralize}")
  end
end
<% cache('all_school_admin_athletes') do %>
  <% users.each do |row_users| %>
    <div class="row">
      <% row_users.each do |user| %>
        <%= render user %>
      <% end %>
    </div>
  <% end %>
<% end %>
config.autoload_paths += %W(
  #{config.root}
  #{config.root}/lib
  #{config.root}/app/models
  #{config.root}/app/models/concerns
  #{config.root}/app/sweepers
)

# Activate observers that should always be running.
config.active_record.observers = :user_sweeper