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 `status_tag' for NodeDecorator #2874
Comments
Currently the StatusTag component is only available within an Arbre context. I've added an application helper in the past to facilitate that type of usage: # application_helper.rb
def status_tag(status)
content_tag(:span, status, class: "status_tag #{status.titleize.gsub(/\s/,'').underscore}")
end But then again, it would also be useful to provide a compatible method to access |
A context can be passed to the decorator. Can I access that abre context somehow an pass it on? Maybe that would be sufficient. |
You can set up a helper that will let you use Arbre: # app/helpers/application_helper.rb
module ApplicationHelper
def arbre(&block)
Arbre::Context.new(&block).to_s
end
end # app/decorators/foo_decorator.rb
class FooDecorator < Draper::Decorator
def wheelchair
arbre do
status_tag model.wheelchair, class: model.wheelchair
end
end
end |
Thx a lot, that looks pretty neat. But what about performance? On a list of 100 Nodes and lets say 3 different columns, that would be 300 times a new Arbre::Context. Is it expensive to create a new context? I'll give it a try. |
Creating 100 |
Hello guys, what is proper way to use this peace of code #2874 (comment)? UPS. Resolved we just need to pass decorator object as helper (2nd argument in Arbre::Context constructor) |
@Fivell can you post your code? |
@timoschilling, resolved using this https://gist.github.com/Fivell/81921da21f3d92dc0d22 |
I think, there is another problem with this approach. Some helpers are not defined in arbre context. For example in https://gist.github.com/cpfarher/d96cdb0c4de617237c7e#file-recipe_recorator-rb-L16 .... is there any solution for this kind of problem? |
I can confirm @seanlinsley's example works with Draper Decorators also. You don't have to add the Gem Versions
Code Exampleclass FooDecorator < Draper::Decorator
delegate_all
def aasm_state
foo_instance = object
#use foo_instance so the block doesn't get confused since `object` is already a method inside of an Arbre Context.
arbre { status_tag(foo_instance.aasm_state, :ok) }
end
def some_boolean_field
object.some_boolean_field? ? arbre { status_tag( "yes", :ok ) } : arbre { status_tag( "no" ) }
end
private
def arbre(&block)
Arbre::Context.new(&block).to_s
end
end |
At some point between my last comment in 2018 and now, there's been a change in Rails and/or ActiveAdmin which is causing the previously suggested solutions to be HTML Escaped. That said, the following worked for me in present day on Rails 6.0.3.2 and ActiveAdmin 2.7.0. Creating instances of ActiveAdmin::Views::StatusTag and calling class FooDecorator < ApplicationDecorator
delegate_all
def active
object.active? ? status_tag( 'yes', class: 'ok' ) : status_tag( 'no' )
end
end
class ApplicationDecorator < Draper::Decorator
def status_tag(status, options = {})
ActiveAdmin::Views::StatusTag.new.status_tag(status, options)
end
end |
I added draper support for my app (rails 4, activeadmin 1.0.0.pre, draper 1.3) and created a NodeDecorator with the following method:
But it wouldn't work. Do i have to include AA View helpers manually? Maybe you can update the decorators documentation.
Cheers
The text was updated successfully, but these errors were encountered: