Hello, when I generate the adminstrate pages I have this error in one of my model (Pro)
the model :
class Pro < ApplicationRecord
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :masqueradable, :database_authenticatable, :registerable, :recoverable, :rememberable, :validatable, :omniauthable
has_person_name
has_many :rdvs
has_many :notification_pros, foreign_key: :recipient_id
has_many :service_pros
has_many :periods
belongs_to :establishment, optional: true
end
The routes:
require 'sidekiq/web'
Rails.application.routes.draw do
get '/periods/weeks', to: 'periods#week', as: 'new_periods_weeks'
post '/periods/weeks', to: 'periods#new_week', as: 'create_periods_weeks'
resources :periods
scope '/establishments/:establishment' do
resources :prestations
end
resources :establishments
resources :employees
namespace :admin do
resources :pros
resources :users
resources :announcement_pros
resources :notification_pros
resources :service_pros
resources :periods
resources :establishments
resources :prestations
resources :rdvs
root to: "pros#index"
end
get '/privacy', to: 'home#privacy'
get '/terms', to: 'home#terms'
authenticate :pro, lambda { |u| u.admin? } do
mount Sidekiq::Web => '/sidekiq'
end
resources :notification_pros, only: [:index]
resources :announcement_pros, only: [:index]
devise_for :pros, controllers: { omniauth_callbacks: "pros/omniauth_callbacks" }
root to: 'home#index'
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
end
I found the secnd model link with his error
class Period < ApplicationRecord
belongs_to :pro
belongs_to :establishment
end
but I can't find the probleme
The pro dashboard :
require "administrate/base_dashboard"
class ProDashboard < Administrate::BaseDashboard
# ATTRIBUTE_TYPES
# a hash that describes the type of each of the model's fields.
#
# Each different type represents an Administrate::Field object,
# which determines how the attribute is displayed
# on pages throughout the dashboard.
ATTRIBUTE_TYPES = {
notification_pros: Field::HasMany,
service_pros: Field::HasMany,
periods: Field::HasMany,
establishment: Field::BelongsTo,
rdvs: Field::HasMany,
id: Field::Number,
email: Field::String,
encrypted_password: Field::String,
reset_password_token: Field::String,
reset_password_sent_at: Field::DateTime,
remember_created_at: Field::DateTime,
first_name: Field::String,
last_name: Field::String,
announcements_last_read_at: Field::DateTime,
admin: Field::Boolean,
created_at: Field::DateTime,
updated_at: Field::DateTime,
typ: Field::Number,
}.freeze
# COLLECTION_ATTRIBUTES
# an array of attributes that will be displayed on the model's index page.
#
# By default, it's limited to four items to reduce clutter on index pages.
# Feel free to add, remove, or rearrange items.
COLLECTION_ATTRIBUTES = [
:notification_pros,
:service_pros,
:periods,
:establishment,
].freeze
# SHOW_PAGE_ATTRIBUTES
# an array of attributes that will be displayed on the model's show page.
SHOW_PAGE_ATTRIBUTES = [
:notification_pros,
:service_pros,
:periods,
:establishment,
:rdvs,
:id,
:email,
:encrypted_password,
:reset_password_token,
:reset_password_sent_at,
:remember_created_at,
:first_name,
:last_name,
:announcements_last_read_at,
:admin,
:created_at,
:updated_at,
:typ,
].freeze
# FORM_ATTRIBUTES
# an array of attributes that will be displayed
# on the model's form (`new` and `edit`) pages.
FORM_ATTRIBUTES = [
:notification_pros,
:service_pros,
:periods,
:establishment,
:rdvs,
:email,
:encrypted_password,
:reset_password_token,
:reset_password_sent_at,
:remember_created_at,
:first_name,
:last_name,
:announcements_last_read_at,
:admin,
:typ,
].freeze
# Overwrite this method to customize how pros are displayed
# across all pages of the admin dashboard.
#
# def display_resource(pro)
# "Pro ##{pro.id}"
# end
end
I have the same issue. When adding a Field::HasMany attribute and showing an object in administrate that as some relations in the has_many side.
Have you found a fix?
@jean-francois-labbe bonjour,
J'ai totalement r茅installer la gem et 莽a a march茅.
This might be a matter of restarting Spring (./bin/spring stop). If anyone is still seeing it, please let us know here. Meanwhile I'm going to close.
Hey there, we're seeing the same error in our system as well.
@tylerdavis - Does restarting Spring (or the whole computer) help? If not, can you provide an exception backtrace, as well as some details like the original reporter above? Thank you!
@pablobm apologies, I missed your response. This is happening on production for us. Here's a recent event - https://sentry.io/share/issue/a4806402bae54a0cbfe505d5b80b7814/
Please let me know if there's any other information I can provide.
Can you open an a new issue, and (like this one) show what your model layout looks like?
For anyone else running into this issue, I too ran into this with my "Users" show page. I spent some time digging into it and found a workaround (for my application at least).
I generated the HasMany field partials using rails generate administrate:views:field has_many.
Inside app/view/fields/has_many/_show.html.erb I added the following, after page_number is set and before the collection is rendered:
<% page ||= Administrate::Page::Show.new(UserDashboard.new, field.resource) %>
This works for me and all other dashboard still render normally. Again, this is for may specific application, I was only having the issue on my "Users" show page. Still, I hope this at least helps.
Thank you for that Sentry link. I'm pasting here what I think is the most relevant excerpt:
NameError: undefined local variable or method `page' for #<#<Class:0x000055bb97918f68>:0x00007f2b745589e8>
from /usr/local/bundle/gems/administrate-0.13.0/app/views/fields/has_many/_show.html.erb:28:in `__usr_local_bundle_gems_administrate________app_views_fields_has_many__show_html_erb___3015974621036392267_69912306284280'
from action_view/renderer/renderer.rb:61:in `render_template_to_object'
from action_view/renderer/renderer.rb:29:in `render_to_object'
from action_view/rendering.rb:118:in `block in _render_template'
from action_view/base.rb:304:in `in_rendering_context'
from action_view/rendering.rb:117:in `_render_template'
from action_controller/metal/streaming.rb:219:in `_render_template'
from action_view/rendering.rb:103:in `render_to_body'
from action_controller/metal/rendering.rb:52:in `render_to_body'
from action_controller/metal/renderers.rb:142:in `render_to_body'
from abstract_controller/rendering.rb:25:in `render'
from action_controller/metal/rendering.rb:36:in `render'
from action_controller/metal/instrumentation.rb:44:in `block (2 levels) in render'
from active_support/core_ext/benchmark.rb:14:in `block in ms'
from benchmark.rb:308:in `realtime'
from active_support/core_ext/benchmark.rb:14:in `ms'
from action_controller/metal/instrumentation.rb:44:in `block in render'
from action_controller/metal/instrumentation.rb:85:in `cleanup_view_runtime'
from active_record/railties/controller_runtime.rb:34:in `cleanup_view_runtime'
from action_controller/metal/instrumentation.rb:43:in `render'
from meta_tags/controller_helper.rb:22:in `render'
from administrate/application_controller.rb:24:in `show'
...
Something that confuses me is how the exception backtrace doesn't list any Administrate code between the _show.html.erb partial (top of the stack) and administrate/application_controller.rb (bottom of my excerpt). Is this perhaps only the "framework" trace, filtering out the "app" trace? If this is the case, could it be that your app is using a custom administrate/application/show.html.erb template, or a custom render_field helper? Asking for those specifically as I would expect them to appear in between.
I'm going to close this as it's been a while and there's potentially a few things going on here. I'd recommend trying the solution mentioned above and making sure you're using trying the stock show.html.erb or render_field helper, but if none of that helps, please open a new issue.
Most helpful comment
For anyone else running into this issue, I too ran into this with my "Users" show page. I spent some time digging into it and found a workaround (for my application at least).
I generated the
HasManyfield partials usingrails generate administrate:views:field has_many.Inside
app/view/fields/has_many/_show.html.erbI added the following, afterpage_numberis set and before the collection is rendered:This works for me and all other dashboard still render normally. Again, this is for may specific application, I was only having the issue on my "Users" show page. Still, I hope this at least helps.