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

Problems with nested resources #1121

Closed
JelleDekker opened this issue Mar 10, 2012 · 8 comments
Closed

Problems with nested resources #1121

JelleDekker opened this issue Mar 10, 2012 · 8 comments
Labels
Milestone

Comments

@JelleDekker
Copy link

I'm using Active Admin 0.4.2 with Rails 3.2.1, nested resource behave very strange.

Sometimes a "belongs_to" works perfectly fine however I encounter two different cases where it doesn't:

  1. The parent believes the route doesn't exist:
    link_to "child", [:admin, parent, :child] will result in a message that action "show" on admin/child doesn't exist even though "rake routes" reports it does exist. Also when I then go to /admin/parents/:id/children, it exists but I get the following error: "uninitialized constant Parent::Child".

  2. Routing links work fine, but "admin/parents/:id/children" gives "undefined method `find' for nil:NilClass", the same page for the children works fine if I remove the "belongs_to"

  3. Just testing this I got a new one "undefined method `batch_action_admin_series_path'", "Extracted source (around line Resource Collection display name #1):
    1: insert_tag renderer_for(:index)". This seems permanently damaged because this one will not work anymore whatever I do to the controller, even completely back to how it is generated at start by Active Admin doesn't help...

@latortuga
Copy link
Contributor

For your first question, link_to "child", [:admin, parent, :child] for like that to work, you'd need to have an action child defined for parent, when I think you probably want something like link_to "child", [:admin, parent, child].

Please show your code for both the parent and child model admin register blocks. Without this, most of what you said is nigh on impossible to diagnose.

@JelleDekker
Copy link
Author

The code used was actually quite generic, I can't reproduce the error directly now because I now get "undefined method `batch_action_admin_series_path' for #<#Class:0x007fb22db2c7f8:0x007fb22dc0f5a8>" even after I've regenerated the controllers?

But it was:

ActiveAdmin.register User do

index do
   column :name, :sortable => :name do |user|
        link_to user.name, admin_user_path(user)
   end
   column :email 
   column 'Adressen' do |user|
       link_to 'Adressen', [:admin, user, :addresses]
   end
    column :created_at
    column :sign_in_count

    default_actions
  end
ActiveAdmin.register Address do
  belongs_to :user

This worked in this case (user/address), it worked in TestParent/TestChild I made, but it fails in the above described ways when I tried using it with other classes. The 'belongs_to' and 'has_many' were all correctly set in the models.

@latortuga
Copy link
Contributor

Are you using an optional belongs_to in your setup for the child of the relationship? I suspect that #1122 is a similar issue to what you're having for the batch_action being undefined.

@JelleDekker
Copy link
Author

No I'm not using an optional belongs_to, just the ordinary "belongs_to". At the moment I'm using nothing (deleted all and remade the files using $ rails generate active_admid:resource, so they're all 'clean'), but the batch_action being undefined still happens at one of them...

@latortuga
Copy link
Contributor

Where is this series action defined? Did you make it?

@JelleDekker
Copy link
Author

'series' is just the name of the model/resource

So I now did "$ rails generate active_admid:resource Serie" to regenerate the file which had the batch_action problem, and the problem is still there.

@JelleDekker
Copy link
Author

One the problems is solved, the problem is that I accidentally used "Serie - Series" and the singular of "Series" in English is "Series"... So the Rails method that singularizes the name couldn't because of my language error.

Whether problem 2 was also caused by this? I don't know, the strange thing is that that one happened later and was fine in the beginning.

@gregbell
Copy link
Contributor

Looks like this was solved. If this issue still existing, please re-open or create a new issue.

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

No branches or pull requests

3 participants