Add the belongs_to functionality to Page resources #2770

Closed
wants to merge 3 commits into
from

Conversation

Projects
None yet
5 participants
Contributor

zorab47 commented Dec 7, 2013

Allow Page resources to use the same belongs_to functionality as Resource.

ActiveAdmin.register_page "Post Report" do
  belongs_to :post

  content do
    # ...
  end
end
Contributor

zorab47 commented Dec 7, 2013

I'm seeing a strange situation where I'm unable to access the parent object within the Page's content block. It is instead returning the Arbre context's parent node.

Example

ActiveAdmin.register_page "Post Report" do
  belongs_to :post

  content do
    h2 parent.name # <= Here parent should be the Post, but instead is nil
  end
end

Aliasing parent to post fixes the issue:

ActiveAdmin.register_page "Post Report" do
  belongs_to :post

  controller do
    alias_method :post, :parent
    helper_method :post
  end

  content do
    h2 parent.name # Parent is still nil
    h2 post.name   # Works as expected
  end
end

Edit: Updated example

Owner

seanlinsley commented Dec 7, 2013

@zorab47 maybe it'd be good to add a failing test for that

Owner

seanlinsley commented Jan 11, 2014

@zorab47 is the only problem here that parent isn't resolving correctly?

Contributor

zorab47 commented Jan 13, 2014

Yes, I think that is all that remains.

Owner

Fivell commented Jan 25, 2017 edited

@zorab47 , this is very nice feature, maybe you could remember why there is a conflict with arbre parent method when using page, and no conflict when using resource?

varyonic added the feature label Jan 25, 2017

Fivell referenced this pull request Jan 25, 2017

Merged

add belongs to to page resources #4759

4 of 4 tasks complete
Contributor

zorab47 commented Jan 25, 2017

Owner

Fivell commented Jan 25, 2017

@zorab47 , let's give this second chance in #4759

Fivell closed this Jan 25, 2017

zorab47 referenced this pull request in zorab47/active_admin-subnav Feb 22, 2017

Open

[discussion] update to recent activeadmin features #5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment