Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

undefined method `persisted?' for #<ParentLocality::ActiveRecord_Relation:0x007fa4b89bac58> #4752

Closed
snmmaurya opened this issue Jan 25, 2017 · 9 comments

Comments

@snmmaurya
Copy link

snmmaurya commented Jan 25, 2017

I am facing this error at the time of edit and view.

Here error trace:

ActionView::Template::Error (undefined method `persisted?' for #<ParentLocality::ActiveRecord_Relation:0x007fa4b89bac58>):
    1: insert_tag renderer_for(:edit)
  activerecord (4.1.8) lib/active_record/relation/delegation.rb:136:in `method_missing'
  activerecord (4.1.8) lib/active_record/relation/delegation.rb:99:in `method_missing'
  /home/snm/.rvm/gems/ruby-2.0.0-p648@holachef2/bundleractiveadmin (7aef260921d4) lib/active_admin/views/pages/form.rb:36:in `default_form_path'
  /home/snm/.rvm/gems/ruby-2.0.0-p648@holachef2/bundleractiveadmin (7aef260921d4) lib/active_admin/views/pages/form.rb:30:in `default_form_options'
  /home/snm/.rvm/gems/ruby-2.0.0-p648@holachef2/bundleractiveadmin (7aef260921d4) lib/active_admin/views/pages/form.rb:17:in `main_content'
  /home/snm/.rvm/gems/ruby-2.0.0-p648@holachef2/bundleractiveadmin (7aef260921d4) lib/active_admin/views/pages/base.rb:87:in `block (2 levels) in build_main_content_wrapper'
@timoschilling
Copy link
Member

Please post the admin file of the related source

@deivid-rodriguez
Copy link
Member

Also, your activeadmin version is more than two years old. Could you try upgrading? See https://github.com/activeadmin/activeadmin/wiki.

@dmitry
Copy link
Contributor

dmitry commented Jan 27, 2017

@snmmaurya you are on 2 years old activeadmin (7aef260921d4), please upgrade if you are start to use latest rails version.

@snmmaurya
Copy link
Author

I tried to update activeadmin, but did not get any success

@snmmaurya
Copy link
Author

snmmaurya commented Feb 4, 2017

Here is my code -

ActiveAdmin.register ParentLocality do  
  menu parent: 'Locality Settings', priority: 2
  
  permit_params :name, :use_store_items_from, :city_id, :latitude, :longitude, :display_time_span, :service_area

  filter :name

  form do |f|
    f.inputs do 
      f.input :name
      f.input :city_id, as: :select, collection: City.all, prompt: 'Select City'
      f.input :use_store_items_from, as: :select, collection: ParentLocality.all.collect {|c| [c.name, c.id]}
      f.input :latitude, hint: 'Like 19.00000'
      f.input :longitude, hint: 'Like 72.00000'
      f.input :display_time_span
      f.input :service_area
    end
    f.actions
  end
end

@snmmaurya
Copy link
Author

snmmaurya commented Feb 4, 2017

---- My model Code:--

class ParentLocality < ActiveRecord::Base
  self.table_name = "pin_code_groups"
  acts_as_paranoid

  has_many :children, class_name: "Locality", foreign_key: "pin_code_group_id"
  has_one :sibling_parent, primary_key: "use_store_items_from", foreign_key: "id", class_name: "ParentLocality"  
  has_many :parent_locality_delivery_time_slots, foreign_key: "pin_code_group_id"
  has_many :delivery_time_slots, through: :parent_locality_delivery_time_slots  
  has_many :parent_locality_disable_meal_types, foreign_key: "pin_code_group_id"
  has_many :disable_meals, through: :parent_locality_disable_meal_types, source: :meal_type
  has_many :sold_out_schedules, foreign_key: "pin_code_group_id"  
  has_many :coupons
  has_many :runners
  has_many :wallet_cashbacks
  belongs_to :city
  has_many :parent_locality_banners
  has_many :banners, through: :parent_locality_banners
  has_many :parent_locality_chefs, foreign_key: "pin_code_group_id"
  has_many :chefs, through: :parent_locality_chefs
  has_many :parent_locality_coupons
  has_many :coupons, through: :parent_locality_coupons
  has_many :parent_locality_offers
  has_many :offers, through: :parent_locality_offers
  validates :latitude, :longitude, presence: true
  has_many :parent_locality_service_areas, foreign_key: "pin_code_group_id"

  scope :active, -> {where("archived = false")}

  geocoded_by :name
end

@deivid-rodriguez
Copy link
Member

Please upgrade AA. There's an upgrade document in the wiki that can help.

@snmmaurya
Copy link
Author

snmmaurya commented Mar 3, 2017

I tried after update but did not work.

I put a temporary fix inside admin/parent_locality.rb. Its not correct way, but working fine.

#Temporary fix of exception

  controller do
    def new
      @parent_locality = ParentLocality.new
      super
    end

    def create
      @parent_locality = ParentLocality.new(params.require(:parent_locality).permit(:name, :use_store_items_from, :city_id, :latitude, :longitude, :display_time_span, :service_area, :kiosk))
      super
    end

    def edit
      @parent_locality = ParentLocality.find params[:id]
      super
    end

    def show
      @parent_locality = ParentLocality.find params[:id]
      super
    end

    def update
      @parent_locality = ParentLocality.find params[:id]
      super
    end
  end

@deivid-rodriguez
Copy link
Member

@snmmaurya Since you've workaround the issue, I'm going to close this. Feel free to reopen with reproduction steps if you want this fixed inside AA!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants