arbre
An Object Oriented DOM Tree in Ruby
I am displaying an ActiveAdmin registered model to the user.
ActiveAdmin.register ConfigurationFile do
show do
attributes_table do
row :name
row :filename
row :content
end
end
end
:content
is a string with newlines, but when rendered by Arbre newlines and extra whitespace are dropped.
How can I display :content
without dropping extra whitespace and newlines?
Source: (StackOverflow)
I have this code:
div class: item.ui_type do
link_to image_tag(item.image.image_public_url), item.target)
link_to item.label, item.target
end
Basically, I want a div with 2 links inside. However, only the last element is getting rendered, presumably because what gets rendered inside the body is the return value of the block.
I know I can declare those as an array and join them, but then I need to call html_safe. I'm trying to find a way to do this when you actually don't trust the input that you're receiving.
This seems like it should be an extremely simple thing to do, but I can't find it anywhere.
Any pointers?
Source: (StackOverflow)
I'm trying to run rails g active_admin:install
script after installing of activeadmin
gem. When I run this script I get an error
Could not find arbre-1.0.1 in any of the sources
Run `bundle install` to install missing gems.
Although I've already installed all necessary gems and my app is using arbre
gem:
Using arbre 1.0.1
Gemfile:
source 'https://rubygems.org'
gem 'rails', '4.1.1'
gem 'sqlite3'
gem 'sass-rails', '~> 4.0.3'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.0.0'
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 2.0'
gem 'sdoc', '~> 0.4.0', group: :doc
gem 'spring', group: :development
gem 'devise'
gem 'activeadmin', github: 'gregbell/active_admin'
How can I fix that problem? Thanks!
Source: (StackOverflow)
I am displaying a table with ActiveAdmin using the "Index as Table" functionality:
index :pagination_total => false do
if Ability.new(current_user).can? :manage, :metric
selectable_column
end
column '' do |metric|
links = link_to(metric.icon, admin_metric_path(metric), :title => metric.comment)
links += link_to(metric.data_icon, admin_metric_path(metric)) unless metric.datum_ids.empty?
links
end
column 'Status', :success, sortable: :success do |metric|
metric.success == 1 ? status_tag('Success', :ok) : status_tag('FAILED', :error)
end
column 'When (UTC)', :createddttm
column 'What', :metric_name
column 'Area', :logarea
column 'Subarea', :subarea
column 'Value', :value
column 'Machine', :machine_name, sortable: 'machinename.machinename'
column 'Domain', :domain_name, sortable: 'domain.domainname'
column 'Product', :product_name, sortable: 'product.productname'
column 'Version', :product_version, sortable: 'product.productversion'
column 'Install Type', :install_type, sortable: 'product.productinstalltype'
column 'Lang', :language
column 'Duration', :duration
end
Given that the row data does not change, I would like to add row level caching of the rendered html with a long expiry time but I can't figure out how to hook into the row rendering code in Arbre.
I am currently caching the entire page for 60 seconds but that is not optimal. My cache store is Dalli / memcached.
Source: (StackOverflow)
I have a common pattern or repeated code that I'd like to DRY up in my ActiveAdmin views. I'm using arbre components to render as much of my views as I can and I'd like to keep it that way if possible (i.e. I don't really want to convert to straight up HTML in the normal fashion -- I'm trying to understand the arbre way here). Here's the code I'd like to DRY up:
clients.in_groups_of(3).each do |clients_group|
columns do
clients_group.compact.each do |client|
column do
panel client.name do
# ...
end
end
end
end
end
After reading through the documentation in the arbre gem, I started to try to create my own, custom arbre component. But I was quickly forced to realize that I have no idea how to satisfy arbre. I couldn't figure out how to pass my local variables into the block. For example:
# config/initializers/active_admin.rb
module ActiveAdmin
module Views
class ClientsBreakdown < ActiveAdmin::Component
builder_method :clients_breakdown
def build(clients, attributes = {})
group_size = attributes.delete(:in_groups_of) { 3 }
clients.in_groups_of(group_size).each do |clients_group|
columns do
clients_group.compact.each do |client|
column do
panel client.name do
super(attributes) # Doesn't seem to matter where this `super` call
# is, but I do want to be able to pass `client`
# into the `clients_breakdown` block here
# yield(client) # -- I've also tried adding this.
end
end
end
end
end
end
end
end
end
Then, calling this in my ActiveAdmin User view might look like:
clients_breakdown(Client.all, in_groups_of: 2) do |client|
ul do
li client.name
end
end
Running the above code results in this error:
UPDATE 2 The exception has changed to this after moving my custom component code into the ActiveAdmin::Views
module.

My key issue seems to be that I can't just call yield(client)
where I currently have super(attributes)
. But that's an arbre thing so I don't know what to do there to pass the client into the calling block. Is this the right track or is there another way to DRY this up?
UPDATE 1
I've realized that the call to super
can happen anywhere in the build
method and really has nothing to do with what is output. So even if I move the super(attributes)
call up... I still can't figure out what to put inside of the panel
block so that I can render the rest of my arbre components in there from the call to clients_breakdown
.
Source: (StackOverflow)
I'm having an issue with Active Admin. Here are the versions :
We upgraded to rails 4.2 and had to upgrade activeadmin as well (from 0.5). After a couple of tweaks (especially the authorization system) everything seems to be fine, except for 1 big issue : I can only access the index pages. When going to a page with an ID (for example : "http://localhost:3000/admin/companies/2968"), I am getting this error :
No route matches {:action=>"edit", :controller=>"admin/companies", :format=>nil, :id=> #{User id: nil, [all user attributes with nil value]}}. Missing required keys: [:id]
Looks like the param[:id] got changed to an empty user somehow, which of course makes it break.
Here's what I know :
when putting a binding.pry on top of my ApplicationController and inspecting the params, I get {:action=>"edit", :controller=>"admin/companies", :format=>nil, :id=>2968} (so no problem here)
the lines that raise the error are :
active_admin/resource/show.html.arb
-> arbre/element/builder_method.rb#insert_tag
-> arbre/element/builder_method.rb#build_tag
-> actionpack/actiondispatch/journey/formatter#generate (when this method is called, the path_parameters ID value is already corrupted, which raises the error)
Any idea why my ID parameter is not interpreted correctly / where I could look further ?
EDIT >> I have this in my routes.rb
ActiveAdmin.routes(self)
devise_for :admin_users, ActiveAdmin::Devise.config
And the generated routes look fine with rake routes (in this particular example, I have admin/companies#edit admin_company GET /admin/companies/:id(.:format)
EDIT2 >> In case it wasn't clear, this happens for all show pages.
If I go to http://localhost:3000/admin/projects/ for example, it works fine, but http://localhost:3000/admin/projects/23815 gives me id = empty user as well
Source: (StackOverflow)
I am using on Rails 4 ActiveAdmin and Money-Rails. Is there a way to have two or more inputs in a single line of text?
para "Please enter the amount"
f.input :amount_due_currency, :label => "Dollars ",:input_html => {:style => 'width:3%'}
para "and"
f.input :amount_due_cents, :label => "cents ", :input_html => {:style => 'width:10%'}
para "to deposit on your account."
the output that I need would look like
Please enter the amount __ Dollars and __ cents to deposit on your account.
I tried string interpolation but that fails. Can someone help me please?
Source: (StackOverflow)
I want to try the Arbre gem for rails. There is an example on this page: https://github.com/activeadmin/arbre/blob/master/README.md
Where must I paste the next code?
html = Arbre::Context.new do
h2 "Why is Arbre awesome?"
ul do
li "The DOM is implemented in ruby"
li "You can create object oriented views"
li "Templates suck"
end
end
I want to try the code above, but I don't know where I must paste it. Which file? Which method? I pasted the code into my controller, but it doesn't work.
Source: (StackOverflow)
On Rails 3.2.13, simple_format
does not return what I expect it to do, on an admittedly convoluted case:
> simple_format("a <= 2, b < 4")
"<p>a < 4</p>"
Since this case does not seem to work properly (I'm losing half my string!), is there a way to pre-escape special characters so that it works everywhere?
Source: (StackOverflow)