Rails 3.2 config.cache_classes = true在视图中显示空白值

时间:2014-03-14 17:24:42

标签: ruby-on-rails ruby ruby-on-rails-3

我有一个提交调整请求的模板(show.html.erb)。同样在模板中,我有一个表格,可以分解待定调整和完成调整,向您显示有关您刚刚提交的调整的信息。 EX。类型,原因,创建于。

当我在我的环境/ development.rb中设置config.cache_classes = true时,Pending Adjustments和Completed Adjustments表中的值除了在时间戳创建时不显示。类型或原因不显示。如果我设置config.cache_classes = false,则会显示所有内容。我还设置了config.action_view.cache_template_loading = false,仍然得到相同结果的空表值。

我试图让它与config.cache_classes = true一起使用,因为在生产中我需要为其他事情打开缓存。

控制器/ print_cost_controller.rb

class PrintCostController < ApplicationController
  def show
    @printcost = PrintCost.find(params[:id])
    @order = Core::Order.find(params[:id])
    authorize! :show, @order
    respond_to do |format|
      format.html { render :show }
    end
  end
end

模型/ printcost.rb

class PrintCost < ActiveResource::Base
  self.site = ENV["PRINT_COST_URL"]
  @headers  = { 'Authorization' => "Token token=#{ENV['PRINT_COST_TOKEN']}" }
end

show.html.erb

<% if !@printcost.adjustments.empty? %>
  <div class="adjustments_pending">
    <h4 class="printcost">Pending Adjustments</h4>
    <table class="table">
      <tr>
        <th>Requested On</th>
        <th>Reason</th>
        <th>Type</th>
        <th></th>
      </tr>
    <% @printcost.adjustments.each do |adjustment| %>
      <% if adjustment.completed_at == nil %>
        <tr>
          <td><%= DateTime.parse(adjustment.created_at).in_time_zone("Eastern Time (US & Canada)").strftime("%^b-%d-%y %I:%M:%S %P") %></td>
          <td><%= adjustment.explanation %></td>
          <td><%= adjustment.adjustment_type %></td>
          <td><%= link_to 'X', remove_adjustment_path(adjustment.id), :method => :delete, :class => "badge", "data-title" =>"Cancel Request" %></td>
        </tr>
      <% end %>
    <% end %>
  </table>
  </div>
  <div class="adjustments_completed">
    <h4 class="printcost">Completed Adjustments</h4>
    <table class="table">
      <tr>
        <th>Requested On</th>
        <th>Reason</th>
        <th>Type</th>
        <th>Note</th>
      </tr>
      <% @printcost.adjustments.each do |adjustment| %>
        <% if adjustment.completed_at %>
          <tr>
            <td><%= DateTime.parse(adjustment.completed_at).in_time_zone("Eastern Time (US & Canada)").strftime("%^b-%d-%y %I:%M:%S %P") %></td>
            <td><%= adjustment.adjustment_type == "Tax" ? "$#{adjustment.adjustment_cost} - #{adjustment.explanation}" : adjustment.explanation %></td>
            <td><%= adjustment.adjustment_type %></td>
            <td><%= adjustment.note %></td>
          </tr>
        <% end %>
      <% end %>
    </table>
  </div>
<% end %>

关于为什么会发生这种情况的任何想法?

1 个答案:

答案 0 :(得分:0)

我弄明白了这个问题。这是我称之为调整的另一个模型的问题。不得不重命名。