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

Cannot access resources in show DSL with same name as HTML tags #171

Closed
timriley opened this issue Jun 7, 2011 · 10 comments
Closed

Cannot access resources in show DSL with same name as HTML tags #171

timriley opened this issue Jun 7, 2011 · 10 comments
Labels
Milestone

Comments

@timriley
Copy link

timriley commented Jun 7, 2011

When you have a resource with a name that is the same as an HTML tag, like Article, then you will not be able to access the resource instance.

For example:

ActiveAdmin.register Article do
  show :title => :title do
    attributes_table do
      row :title
      row :author
      row :body do
        md(article.body)
      end
    end
  end  
end

When I'm trying to pass article.body to my md helper method above, the "article" variable is actually an instance of Arbre::HTML::Article, instead of my ActiveRecord subclass.

To work around this, I'm currently doing the following:

ActiveAdmin.register Article do
  show :title => :title do
    _article = @_assigns['article']

    attributes_table do
      row :title
      row :author
      row :body do
        md(_article.body)
      end
    end
  end  
end

But it would probably be good to have some way of handling this more nicely.

@tomkarlo
Copy link

I'm having a similar issue in the dashboard because I have an model named "Label" (it's a fashion site) and it's conflicting with Arbre::HTML::Label ...

section "Recent Labels" do
  ul do
    Label.last(5).collect do |label|
      li link_to(label.name, admin_label_path(label))
    end
end

returns: undefined method `last' for Arbre::HTML::Label:Class

@tomkarlo
Copy link

For now, this is working for me:

ActiveRecord::Base::Label.last(5).collect do |label|

@gregbell
Copy link
Contributor

Thanks for reporting this. I've moved it into the 0.4.0 release as something to deal with.

gregbell added a commit that referenced this issue Aug 17, 2011
Arbre used to include Arbre::HTML in to the view context. This would
include all the tag classes (such as Arbre::HTML::Label) into the view
context. This caused clashes if you already had a Label class defined.
@ghost
Copy link

ghost commented Aug 26, 2011

Same problem here.

@pcreux
Copy link
Contributor

pcreux commented Sep 28, 2011

Fixed in 0.3.0.

@pcreux pcreux closed this as completed Sep 28, 2011
@mark100net
Copy link

Are you sure this is fixed? I'm having this problem with an Area model in 0.5.0.

@aleicher
Copy link

I'm facing the same issue using active admin1.0.0pre
I have an Area model in my rails app, which I want to show in Active Admin.

The workaround as suggested above worked for me, i.e. first get the object from the assigns hash.

  show do
    _area = assigns[:area]
    attributes_table do
      # then use _area to access the area object
    end
  end

@seanlinsley
Copy link
Contributor

@aleicher no matter what your model is named you can always access it by calling resource instead of the alias named specifically for that model.

@aleicher
Copy link

Thx. Seems like I missed that one, works great.

@rendekarf
Copy link

Wow! Had the exact same issue (model named Area) in 2022, checked docs and google'd it with no luck, until I found this issue thread. Cheers @seanlinsley

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

8 participants