Closed cmendla closed 5 years ago
Here it is:
column(:cost) do
format(cost) do
content_tag(:div, cost, style: "text-align:right")
end
end
More info in the wiki.
I am getting a no implicit conversion of BigDecimal into String error. Cost is a bigdecimal. I've tried a couple variations of .to_s but no luck. Thanks
I can not reproduce that locally. Which version of the datagrid, ruby and rails do you use? Can you show me the "Full Trace" tab?
Rails.root: /home/chris/Documents/RailsProjects/mlml
Application Trace | Framework Trace | Full Trace
app/grids/admin_plans_grid.rb:20:in `format'
app/grids/admin_plans_grid.rb:20:in `block in <class:AdminPlansGrid>'
datagrid (1.5.8) lib/datagrid/columns.rb:479:in `instance_eval'
datagrid (1.5.8) lib/datagrid/columns.rb:479:in `block in generic_value'
datagrid (1.5.8) lib/datagrid/columns.rb:497:in `cache'
datagrid (1.5.8) lib/datagrid/columns.rb:470:in `generic_value'
datagrid (1.5.8) lib/datagrid/columns.rb:458:in `block in html_value'
datagrid (1.5.8) lib/datagrid/columns.rb:497:in `cache'
datagrid (1.5.8) lib/datagrid/columns.rb:454:in `html_value'
datagrid (1.5.8) lib/datagrid/renderer.rb:19:in `format_value'
datagrid (1.5.8) lib/datagrid/helper.rb:17:in `datagrid_value'
datagrid (1.5.8) app/views/datagrid/_row.html.erb:3:in `block in __home_chris__rvm_gems_ruby_______gems_datagrid_______app_views_datagrid__row_html_erb___2760100105319245367_70278196898460'
datagrid (1.5.8) app/views/datagrid/_row.html.erb:2:in `each'
datagrid (1.5.8) app/views/datagrid/_row.html.erb:2:in `__home_chris__rvm_gems_ruby_______gems_datagrid_______app_views_datagrid__row_html_erb___2760100105319245367_70278196898460'
actionview (5.2.0) lib/action_view/template.rb:159:in `block in render'
activesupport (5.2.0) lib/active_support/notifications.rb:170:in `instrument'
actionview (5.2.0) lib/action_view/template.rb:354:in `instrument_render_template'
actionview (5.2.0) lib/action_view/template.rb:157:in `render'
actionview (5.2.0) lib/action_view/renderer/partial_renderer.rb:344:in `block in render_partial'
actionview (5.2.0) lib/action_view/renderer/abstract_renderer.rb:44:in `block in instrument'
activesupport (5.2.0) lib/active_support/notifications.rb:168:in `block in instrument'
activesupport (5.2.0) lib/active_support/notifications/instrumenter.rb:23:in `instrument'
activesupport (5.2.0) lib/active_support/notifications.rb:168:in `instrument'
actionview (5.2.0) lib/action_view/renderer/abstract_renderer.rb:43:in `instrument'
actionview (5.2.0) lib/action_view/renderer/partial_renderer.rb:333:in `render_partial'
actionview (5.2.0) lib/action_view/renderer/partial_renderer.rb:312:in `render'
actionview (5.2.0) lib/action_view/renderer/renderer.rb:49:in `render_partial'
actionview (5.2.0) lib/action_view/renderer/renderer.rb:23:in `render'
actionview (5.2.0) lib/action_view/helpers/rendering_helper.rb:34:in `render'
datagrid (1.5.8) lib/datagrid/renderer.rb:98:in `_render_partial'
datagrid (1.5.8) lib/datagrid/renderer.rb:65:in `block in rows'
activerecord (5.2.0) lib/active_record/relation/delegation.rb:41:in `each'
activerecord (5.2.0) lib/active_record/relation/delegation.rb:41:in `each'
datagrid (1.5.8) lib/datagrid/renderer.rb:59:in `map'
datagrid (1.5.8) lib/datagrid/renderer.rb:59:in `rows'
datagrid (1.5.8) lib/datagrid/helper.rb:76:in `datagrid_rows'
datagrid (1.5.8) app/views/datagrid/_table.html.erb:14:in `block in __home_chris__rvm_gems_ruby_______gems_datagrid_______app_views_datagrid__table_html_erb___3400049779050080710_70278196353920'
actionview (5.2.0) lib/action_view/helpers/capture_helper.rb:41:in `block in capture'
actionview (5.2.0) lib/action_view/helpers/capture_helper.rb:205:in `with_output_buffer'
actionview (5.2.0) lib/action_view/helpers/capture_helper.rb:41:in `capture'
actionview (5.2.0) lib/action_view/helpers/tag_helper.rb:272:in `content_tag'
datagrid (1.5.8) app/views/datagrid/_table.html.erb:8:in `__home_chris__rvm_gems_ruby_______gems_datagrid_______app_views_datagrid__table_html_erb___3400049779050080710_70278196353920'
actionview (5.2.0) lib/action_view/template.rb:159:in `block in render'
activesupport (5.2.0) lib/active_support/notifications.rb:170:in `instrument'
actionview (5.2.0) lib/action_view/template.rb:354:in `instrument_render_template'
actionview (5.2.0) lib/action_view/template.rb:157:in `render'
actionview (5.2.0) lib/action_view/renderer/partial_renderer.rb:344:in `block in render_partial'
actionview (5.2.0) lib/action_view/renderer/abstract_renderer.rb:44:in `block in instrument'
activesupport (5.2.0) lib/active_support/notifications.rb:168:in `block in instrument'
activesupport (5.2.0) lib/active_support/notifications/instrumenter.rb:23:in `instrument'
activesupport (5.2.0) lib/active_support/notifications.rb:168:in `instrument'
actionview (5.2.0) lib/action_view/renderer/abstract_renderer.rb:43:in `instrument'
actionview (5.2.0) lib/action_view/renderer/partial_renderer.rb:333:in `render_partial'
actionview (5.2.0) lib/action_view/renderer/partial_renderer.rb:312:in `render'
actionview (5.2.0) lib/action_view/renderer/renderer.rb:49:in `render_partial'
actionview (5.2.0) lib/action_view/renderer/renderer.rb:23:in `render'
actionview (5.2.0) lib/action_view/helpers/rendering_helper.rb:34:in `render'
datagrid (1.5.8) lib/datagrid/renderer.rb:98:in `_render_partial'
datagrid (1.5.8) lib/datagrid/renderer.rb:43:in `table'
datagrid (1.5.8) lib/datagrid/helper.rb:42:in `datagrid_table'
app/views/admin_plans/index.html.erb:4:in `_app_views_admin_plans_index_html_erb__287479146225585526_70278195806060'
actionview (5.2.0) lib/action_view/template.rb:159:in `block in render'
activesupport (5.2.0) lib/active_support/notifications.rb:170:in `instrument'
actionview (5.2.0) lib/action_view/template.rb:354:in `instrument_render_template'
actionview (5.2.0) lib/action_view/template.rb:157:in `render'
actionview (5.2.0) lib/action_view/renderer/template_renderer.rb:54:in `block (2 levels) in render_template'
actionview (5.2.0) lib/action_view/renderer/abstract_renderer.rb:44:in `block in instrument'
activesupport (5.2.0) lib/active_support/notifications.rb:168:in `block in instrument'
activesupport (5.2.0) lib/active_support/notifications/instrumenter.rb:23:in `instrument'
activesupport (5.2.0) lib/active_support/notifications.rb:168:in `instrument'
actionview (5.2.0) lib/action_view/renderer/abstract_renderer.rb:43:in `instrument'
actionview (5.2.0) lib/action_view/renderer/template_renderer.rb:53:in `block in render_template'
actionview (5.2.0) lib/action_view/renderer/template_renderer.rb:61:in `render_with_layout'
actionview (5.2.0) lib/action_view/renderer/template_renderer.rb:52:in `render_template'
actionview (5.2.0) lib/action_view/renderer/template_renderer.rb:16:in `render'
actionview (5.2.0) lib/action_view/renderer/renderer.rb:44:in `render_template'
actionview (5.2.0) lib/action_view/renderer/renderer.rb:25:in `render'
actionview (5.2.0) lib/action_view/rendering.rb:103:in `_render_template'
actionpack (5.2.0) lib/action_controller/metal/streaming.rb:219:in `_render_template'
actionview (5.2.0) lib/action_view/rendering.rb:84:in `render_to_body'
actionpack (5.2.0) lib/action_controller/metal/rendering.rb:52:in `render_to_body'
actionpack (5.2.0) lib/action_controller/metal/renderers.rb:142:in `render_to_body'
actionpack (5.2.0) lib/abstract_controller/rendering.rb:25:in `render'
actionpack (5.2.0) lib/action_controller/metal/rendering.rb:36:in `render'
actionpack (5.2.0) lib/action_controller/metal/instrumentation.rb:46:in `block (2 levels) in render'
activesupport (5.2.0) lib/active_support/core_ext/benchmark.rb:14:in `block in ms'
/home/chris/.rvm/rubies/ruby-2.4.1/lib/ruby/2.4.0/benchmark.rb:308:in `realtime'
activesupport (5.2.0) lib/active_support/core_ext/benchmark.rb:14:in `ms'
actionpack (5.2.0) lib/action_controller/metal/instrumentation.rb:46:in `block in render'
actionpack (5.2.0) lib/action_controller/metal/instrumentation.rb:87:in `cleanup_view_runtime'
activerecord (5.2.0) lib/active_record/railties/controller_runtime.rb:31:in `cleanup_view_runtime'
actionpack (5.2.0) lib/action_controller/metal/instrumentation.rb:45:in `render'
actionpack (5.2.0) lib/action_controller/metal/implicit_render.rb:35:in `default_render'
actionpack (5.2.0) lib/action_controller/metal/basic_implicit_render.rb:6:in `block in send_action'
actionpack (5.2.0) lib/action_controller/metal/basic_implicit_render.rb:6:in `tap'
actionpack (5.2.0) lib/action_controller/metal/basic_implicit_render.rb:6:in `send_action'
actionpack (5.2.0) lib/abstract_controller/base.rb:194:in `process_action'
actionpack (5.2.0) lib/action_controller/metal/rendering.rb:30:in `process_action'
actionpack (5.2.0) lib/abstract_controller/callbacks.rb:42:in `block in process_action'
activesupport (5.2.0) lib/active_support/callbacks.rb:132:in `run_callbacks'
actionpack (5.2.0) lib/abstract_controller/callbacks.rb:41:in `process_action'
actionpack (5.2.0) lib/action_controller/metal/rescue.rb:22:in `process_action'
actionpack (5.2.0) lib/action_controller/metal/instrumentation.rb:34:in `block in process_action'
activesupport (5.2.0) lib/active_support/notifications.rb:168:in `block in instrument'
activesupport (5.2.0) lib/active_support/notifications/instrumenter.rb:23:in `instrument'
activesupport (5.2.0) lib/active_support/notifications.rb:168:in `instrument'
actionpack (5.2.0) lib/action_controller/metal/instrumentation.rb:32:in `process_action'
actionpack (5.2.0) lib/action_controller/metal/params_wrapper.rb:256:in `process_action'
activerecord (5.2.0) lib/active_record/railties/controller_runtime.rb:24:in `process_action'
actionpack (5.2.0) lib/abstract_controller/base.rb:134:in `process'
actionview (5.2.0) lib/action_view/rendering.rb:32:in `process'
actionpack (5.2.0) lib/action_controller/metal.rb:191:in `dispatch'
actionpack (5.2.0) lib/action_controller/metal.rb:252:in `dispatch'
actionpack (5.2.0) lib/action_dispatch/routing/route_set.rb:52:in `dispatch'
actionpack (5.2.0) lib/action_dispatch/routing/route_set.rb:34:in `serve'
actionpack (5.2.0) lib/action_dispatch/journey/router.rb:52:in `block in serve'
actionpack (5.2.0) lib/action_dispatch/journey/router.rb:35:in `each'
actionpack (5.2.0) lib/action_dispatch/journey/router.rb:35:in `serve'
actionpack (5.2.0) lib/action_dispatch/routing/route_set.rb:840:in `call'
warden (1.2.7) lib/warden/manager.rb:36:in `block in call'
warden (1.2.7) lib/warden/manager.rb:35:in `catch'
warden (1.2.7) lib/warden/manager.rb:35:in `call'
rack (2.0.5) lib/rack/tempfile_reaper.rb:15:in `call'
rack (2.0.5) lib/rack/etag.rb:25:in `call'
rack (2.0.5) lib/rack/conditional_get.rb:25:in `call'
rack (2.0.5) lib/rack/head.rb:12:in `call'
actionpack (5.2.0) lib/action_dispatch/http/content_security_policy.rb:18:in `call'
rack (2.0.5) lib/rack/session/abstract/id.rb:232:in `context'
rack (2.0.5) lib/rack/session/abstract/id.rb:226:in `call'
actionpack (5.2.0) lib/action_dispatch/middleware/cookies.rb:670:in `call'
activerecord (5.2.0) lib/active_record/migration.rb:559:in `call'
actionpack (5.2.0) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
activesupport (5.2.0) lib/active_support/callbacks.rb:98:in `run_callbacks'
actionpack (5.2.0) lib/action_dispatch/middleware/callbacks.rb:26:in `call'
actionpack (5.2.0) lib/action_dispatch/middleware/executor.rb:14:in `call'
actionpack (5.2.0) lib/action_dispatch/middleware/debug_exceptions.rb:61:in `call'
web-console (3.6.2) lib/web_console/middleware.rb:135:in `call_app'
web-console (3.6.2) lib/web_console/middleware.rb:30:in `block in call'
web-console (3.6.2) lib/web_console/middleware.rb:20:in `catch'
web-console (3.6.2) lib/web_console/middleware.rb:20:in `call'
actionpack (5.2.0) lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
railties (5.2.0) lib/rails/rack/logger.rb:38:in `call_app'
railties (5.2.0) lib/rails/rack/logger.rb:26:in `block in call'
activesupport (5.2.0) lib/active_support/tagged_logging.rb:71:in `block in tagged'
activesupport (5.2.0) lib/active_support/tagged_logging.rb:28:in `tagged'
activesupport (5.2.0) lib/active_support/tagged_logging.rb:71:in `tagged'
railties (5.2.0) lib/rails/rack/logger.rb:26:in `call'
sprockets-rails (3.2.1) lib/sprockets/rails/quiet_assets.rb:13:in `call'
actionpack (5.2.0) lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
actionpack (5.2.0) lib/action_dispatch/middleware/request_id.rb:27:in `call'
rack (2.0.5) lib/rack/method_override.rb:22:in `call'
rack (2.0.5) lib/rack/runtime.rb:22:in `call'
activesupport (5.2.0) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
actionpack (5.2.0) lib/action_dispatch/middleware/executor.rb:14:in `call'
actionpack (5.2.0) lib/action_dispatch/middleware/static.rb:127:in `call'
rack (2.0.5) lib/rack/sendfile.rb:111:in `call'
railties (5.2.0) lib/rails/engine.rb:524:in `call'
rack (2.0.5) lib/rack/handler/webrick.rb:86:in `service'
/home/chris/.rvm/rubies/ruby-2.4.1/lib/ruby/2.4.0/webrick/httpserver.rb:140:in `service'
/home/chris/.rvm/rubies/ruby-2.4.1/lib/ruby/2.4.0/webrick/httpserver.rb:96:in `run'
/home/chris/.rvm/rubies/ruby-2.4.1/lib/ruby/2.4.0/webrick/server.rb:290:in `block in start_thread'
ActionView::Template::Error (no implicit conversion of BigDecimal into String):
1: <tr>
2: <% grid.html_columns(*options[:columns]).each do |column| %>
3: <td class="<%= datagrid_column_classes(grid, column) %>"><%= datagrid_value(grid, column, asset) %></td>
4: <% end %>
5: </tr>
Rails 5.2.0 ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-linux] datagrid (1.5.8)
create_table "plans", force: :cascade do |t|
t.string "name"
t.string "term"
t.decimal "cost"
t.string "plan_type"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
Please let me know if you need anything else
Thanks
Here is my whole admin_plans.rb
class AdminPlansGrid < BaseGrid
scope do
Plan
end
filter(:id, :integer)
filter(:created_at, :date, :range => true)
filter(:plan_type)
column(:id)
column(:name)
column(:term)
#column(:cost) do
# style="text-align:right"
# self.cost
#end
column(:cost) do
format(cost) do
content_tag(:div, cost, style: "text-align: right")
end
end
column(:plan_type)
date_column(:created_at)
column(:actions, html: true) do |model|
# link_to "Show", admin_plan
end
end
# + link_to "Edit", edit_plan_path(plan)
One other thing I should mention. I'm using Datagrid on an existing model. Not sure if that makes a difference. IE I did the scaffold for admin_plan but I'm using the plan model in my grid.
Please try no instance eval:
column(:cost) do |model|
format(model.cost) do
content_tag(:div, model.cost, style: "text-align: right")
end
end
Thank you !! That works. The column is right aligned.
I am attempting to use the datagrid gem in a project. I want to have a numeric column right aligned and can't seem to do that.
My admin_plans_grid.rb is
I've been trying variations on the cost column such as what is shown above
I've tried span and a few other ideas but nothing worked.
Question - How can I get the data in the cost column to right or decimal align?