As am working on the Active Admin(0.5) with Rails 3.2.3 Using Multilingual Support using Globalise 3 .
When am running application on local under development & production environment everything works great.
But when i deployed it on to the heroku production mode it throwing me error with the same code am using over local.
When i click on create new page it giving me below error:
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'
Please find below the code
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
I tried to connect with console through heroku & it fetching the models.
I also checked the postgres database over local in production ode & all worked like a charm.
Right now am using Sqlite & postgres over local & heroku as postgres.
Your Help & guidance will be highly appreciable & deserves a hat off from my side.
Please let me know if any more details required.
Right now am using Polymorphic Association
as below
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
Actually am using active admin & in this we don't define @home_tamplate anywhere but in local or dev phase its working fine but when i uploaded it to heroku its start throwing error. Sometime when i restart the heroku it worked but other controller stop working.Its occurring very randomly over heroku with all controllers. I introduced the new & update statement & when i on this it worked for new but when i submit to create it again i get the home_template nil.......
Aucun commentaire:
Enregistrer un commentaire