Ruby on rails 3 Heroku Production Rails(3.2.3)活动管理(0.5)创建和维护中的Globalize 3命名错误;更新
我正在使用globalise3的多语言支持,使用rails3.2.3进行活动管理(0.5) 当我在本地开发和生产环境下运行应用程序时,一切都很好 但当我将它部署到heroku生产模式时,它会给我抛出错误,代码与我在本地使用的代码相同 当我单击“创建新页面”时,会出现以下错误:Ruby on rails 3 Heroku Production Rails(3.2.3)活动管理(0.5)创建和维护中的Globalize 3命名错误;更新,ruby-on-rails-3,heroku,ruby-on-rails-3.2,rubygems,heroku-postgres,Ruby On Rails 3,Heroku,Ruby On Rails 3.2,Rubygems,Heroku Postgres,我正在使用globalise3的多语言支持,使用rails3.2.3进行活动管理(0.5) 当我在本地开发和生产环境下运行应用程序时,一切都很好 但当我将它部署到heroku生产模式时,它会给我抛出错误,代码与我在本地使用的代码相同 当我单击“创建新页面”时,会出现以下错误: NoMethodError in Admin::HomeTemplatesController#new undefined method `build_app_page' for nil:NilClass Rails.r
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与console连接&它获取模型
我还通过本地制作的ode检查了postgres数据库&所有这些都非常有效
现在我使用Sqlite和postgres而不是local和heroku作为postgres
您的帮助和指导将是非常值得赞赏的,值得我敬佩
如果需要更多的细节,请告诉我
现在我正在使用多态关联
如下
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
class HomeTemplate:templatable
有很多:主页\u横幅\u图像,:dependent=>:destroy
接受:home\u banner\u图像的\u嵌套属性\u,:allow\u destroy=>true
接受:应用程序页面的\u嵌套\u属性\u
验证是否存在:应用程序页面
结束
AppPages作为:
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
class-AppPage“AdminUser”
验证是否存在:上次修改的
属于:templatable,:多态=>true,:依赖=>:destroy
有很多:应用程序页面标注
充当嵌套集
属性只读:隐藏
属性只读:受保护
默认范围:order=>'lft ASC'
验证是否存在:name
#验证:name,:scope=>:app\u实例\u id的唯一性
验证:app\u page\u角色的唯一性,:scope=>:app\u实例\u id
挂载上传器:相关pdf,pdf上传器
验证:父\u必须\u属于\u同一\u应用\u实例
#验证以下内容的包含:linked_model,:in=>AppPage.allowed_linked_models,:除非=>Proc.new{{app_page{app_page.linked_model.blank?}
属性可访问:名称、副标题、正文、应用程序页面属性、,
:app\u实例\u id、:app\u页面\u角色、:相关\u pdf、,
:父项\u id,:转换\u属性,
:last_modified_by,:app_instance,:sort,:view_controller,:hidden,:protected,:app_page_callout,:parent
活动管理翻译为:姓名、副标题、正文
#验证:name,:scope=>:locale的全局唯一性
def父对象必须属于同一个应用程序实例
如果!self.parent_id.nil?&self.parent.app_实例_id!=self.app\u实例\u id
错误。添加(:parent\u id,“父项必须属于同一个应用程序实例。”)
结束
结束
def设置视图控制器
如果self.view\u controller.nil?
self.view\u controller=“详细信息”
结束
结束
结束
实际上,我使用的是activeadmin&在这里,我们没有在任何地方定义@home\u tamplate,但在本地或开发阶段,它工作正常,但当我将它上传到heroku时,它的开始抛出错误。有时当我重新启动heroku时,它工作了,但其他控制器停止工作。它在heroku上与所有控制器一起随机发生。我介绍了new&update语句&当我在上面介绍它时,它为new工作,但是当我提交再次创建它时,我得到了home\u模板nil 有人给我回信吗?有人给我回信吗?