【问题标题】:Cant get SQL object from another class无法从另一个类获取 SQL 对象
【发布时间】:2015-09-15 13:08:11
【问题描述】:

我有一个 RefineryCMS 的扩展程序。在该扩展中,我需要从 PagesController 中的对象块获取数据。

我的代码:

def show
  if should_skip_to_first_child?
    redirect_to refinery.url_for(first_live_child.url) and return
  elsif page.link_url.present?
    redirect_to page.link_url and return
  elsif should_redirect_to_friendly_url?
    redirect_to refinery.url_for(page.url), :status => 301 and return
  end

  @block = Refinery::Blocks::BlocksController::Block.find_by(:name => 'Footer')

  render_with_templates?
end

在开发中第一次启动成功,但在刷新或重定向到另一个站点的页面之后:

uninitialized constant Refinery::Blocks::BlocksController::Block

【问题讨论】:

    标签: ruby-on-rails refinerycms


    【解决方案1】:

    你能粘贴你的控制器和模型的整个代码吗? 我认为这行有问题。 @block = Refinery::Blocks::BlocksController::Block.find_by(:name => 'Footer') 您正在尝试从控制器访问。 使用模型名称,如 Module::Model.find_by(:name => "Footer")

    回答:https://github.com/refinery/refinerycms/issues/3051

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-09-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-19
      • 1970-01-01
      • 2016-09-06
      相关资源
      最近更新 更多