Heroku Production Rails(3.2.3)Active admin(0.5)Globalize 3 NoMethodError in create&更新

时间:2015-08-03 12:30:14

标签: ruby-on-rails-3 heroku ruby-on-rails-3.2 rubygems heroku-postgres

正在使用Rails 3.2.3使用Globalize 3使用多语言支持使用Active Admin(0.5)。

当我在本地开发应用程序时正在开发&生产环境一切都很好。

但是当我将它部署到heroku生产模式时,它会使用相同的代码向我抛出错误,而不是使用本地代码。

当我点击创建新页面时,它会给我以下错误:

NoMethodError in Admin::HomeTemplatesController#new

undefined method `build_app_page' for nil:NilClass
Rails.root: /app

Application Trace | Framework Trace | Full Trace
app/admin/home_templates.rb:16:in `new'

请在下面找到代码

ActiveAdmin.register HomeTemplate do

    menu false
  config.clear_action_items!

    form :partial => "form"

    controller do
        protect_from_forgery :except => :sort

    def new
      # @home_template  =HomeTemplate.new
      # if !!current_ability.attributes_for(:create, HomeTemplate)[:app_instance_id]
      #   @valid_parents = AppPage.where("app_instance_id = ? AND parent_id IS NULL", current_ability.attributes_for(:create, HomeTemplate)[:app_instance_id])
      # end
      @home_template.build_app_page
    end

    def create

      # if !!current_ability.attributes_for(:create, HomeTemplate)[:app_instance_id]
      #   @valid_parents = AppPage.where("app_instance_id = ? AND parent_id IS NULL", current_ability.attributes_for(:create, HomeTemplate)[:app_instance_id])
      # end
      if @home_template.present?
      @home_template.app_page.protected = false;
      @home_template.app_page.hidden = false;
      @home_template.app_page.app_instance = @home_template.app_instance;
      create!
      end
    end

    def update
      #@home_template = HomeTemplate.find(params[:id])
      @valid_parents = AppPage.where("app_instance_id = ? AND parent_id IS NULL", @home_template.app_page.app_instance_id)
      update!
    end

    def edit
       # if !!current_ability.attributes_for(:edit, HomeTemplate)[:app_instance_id]
       #   @valid_parents = AppPage.where("app_instance_id = ? AND parent_id IS NULL", current_ability.attributes_for(:edit, HomeTemplate)[:app_instance_id])
       #   Rails.logger.info( @valid_parents)
       #   Rails.logger.info( current_ability.attributes_for(:edit, HomeTemplate)[:app_instance_id])
       # end
       Rails.logger.info( "Home template outside")
       #@home_template = HomeTemplate.find(params[:id])
       @valid_parents = AppPage.where("app_instance_id = ? AND parent_id IS NULL", @home_template.app_page.app_instance_id)
       Rails.logger.info(@valid_parents)
    end

  end

  collection_action :sort, :method => :post do
    if(params[:ids])
      params[:ids].each_with_index do |id, index|
        app_page = AppPage.find(id)
        app_page.move_to_child_of app_page.parent_id if can? :update, app_page.templatable
      end
    end
    head 200
  end

end

我试图通过heroku& amp;它取得了模型。

我还在本地生产的ode& amp;中检查了postgres数据库。一切都像魅力一样。

现在正在使用Sqlite& postgres over local& heroku作为postgres。

你的帮助&指导将非常明显和值得一试帽子。

如果需要更多详细信息,请与我们联系。

目前正在使用Polymorphic Association

如下

class HomeTemplate < ActiveRecord::Base

  include BelongsToAppInstance


  has_one :app_page, :as => :templatable
  has_many :home_banner_images, :dependent => :destroy

  accepts_nested_attributes_for :home_banner_images, :allow_destroy => true
  accepts_nested_attributes_for :app_page
  validates_presence_of :app_page

end

AppPages as:

class AppPage < ActiveRecord::Base

  include BelongsToAppInstance
  belongs_to :last_modified_by, :class_name => "AdminUser"
  validates_presence_of :last_modified_by

  belongs_to :templatable, :polymorphic => true, :dependent => :destroy
  has_many :app_page_callouts
  acts_as_nested_set

  attr_readonly :hidden
  attr_readonly :protected

  default_scope :order => 'lft ASC'

  validates_presence_of :name
  #validates_uniqueness_of :name, :scope => :app_instance_id
  validates_uniqueness_of :app_page_role, :scope => :app_instance_id

  mount_uploader :related_pdf, PdfUploader

  validate :parent_must_belong_to_same_app_instance
  #validates_inclusion_of :linked_model, :in => AppPage.allowable_linked_models, :unless => Proc.new {|app_page| app_page.linked_model.blank? }
  attr_accessible :name,:subtitle,:body,:app_page_attributes,
                  :app_instance_id,:app_page_role,:related_pdf,
                  :parent_id,:translations_attributes,
                  :last_modified_by,:app_instance,:sort,:view_controller,:hidden,:protected,:app_page_callouts,:parent
  active_admin_translates :name,:subtitle,:body
  #validates_globalized_uniqueness_of :name,:scope => :locale
  def parent_must_belong_to_same_app_instance
    if !self.parent_id.nil? && self.parent.app_instance_id != self.app_instance_id 
      errors.add(:parent_id, "The parent must belong to the same app instance.")
    end
  end
  def set_view_controller
    if self.view_controller.nil?
      self.view_controller = "detail"
    end
  end
end

实际上我正在使用主动管理员&amp;在这个我们没有定义@home_tamplate任何地方,但在本地或开发阶段它的工作正常,但当我上传到heroku时,它开始抛出错误。有时当我重新启动heroku它工作但其他控制器停止工作。它在heroku上随机发生所有控制器。我介绍了新的&amp;更新声明&amp;当我在这上面它工作新,但当我提交再次创建它我得到home_template nil .......

0 个答案:

没有答案