violet_rails
violet_rails copied to clipboard
[feature] API HTML renderer
Addresses: https://github.com/restarone/violet_rails/issues/267
Demo
https://user-images.githubusercontent.com/35935196/185770631-67a9aed9-bc09-47bd-b437-17e35cc824c6.mov
HOW TO USE
Api Resource Index
- create snippet with identifier same as api_namespace slug
- Variables available on snippet: @api_resources & @api_namespace
- Render the snippet on any page with this helper: {{cms:helper render_api_namespace_resource_index 'identifier'}}
- Is filterable using query params, eg: http://lvh.me:5250/?properties={"synced":"false"}
Api Resource show
- create snippet with identifier as api_namespace slug with '-show' at the end, eg: people-show
- Variables available on snippet: @api_resource & @api_namespace
- Render the snippet on any page with this helper: {{cms:helper render_api_namespace_resource 'identifier'}}
- id query params is mandetory, will raise 404 otherwise. eg: http://lvh.me:5250/?id=123
{{ cms:helper api_namespace_resource_index 'slug', scope: { properties: { property: value } } }}
Acceptance criteria (for being promoted to nikean.org)
- General regression pass - Heroku ✅
- Ability to query and sort ✅
- Client eng QA ✅ - implement similar workflow to Nikean with search/sort
- General regression pass -
staging⌛
Todo
-
Better documentation for the querying API
-
add in line documentation to indicate that ERB can be used in snippets
-
Change API for querying / sorting. The order key should be at the same level as the scope key
eg:
{{ cms:helper render_api_namespace_resource_index 'cars', scope: { properties: { published: 'true' } }, order: { created_at: 'DESC' } }}
when you visit
https://violetrails.herokuapp.com/nikean-test-details-page?id=463
2022-09-06T21:13:58.303371+00:00 app[web.1]: W, [2022-09-06T21:13:58.303330 #12] WARN -- : [52ea5fcb-2ef3-4156-91e8-051229210180] An error occurred when sending a notification using 'violet_rails_error' notifier.Mailgun::CommunicationError: 401 Unauthorized: Forbidden
2022-09-06T21:13:58.303373+00:00 app[web.1]: /app/vendor/bundle/ruby/3.0.0/gems/mailgun-ruby-1.2.4/lib/mailgun/client.rb:112:in `rescue in post'
2022-09-06T21:13:58.303375+00:00 app[web.1]: /app/vendor/bundle/ruby/3.0.0/gems/mailgun-ruby-1.2.4/lib/mailgun/client.rb:108:in `post'
2022-09-06T21:13:58.303375+00:00 app[web.1]: /app/vendor/bundle/ruby/3.0.0/gems/mailgun-ruby-1.2.4/lib/mailgun/client.rb:92:in `send_message'
2022-09-06T21:13:58.303375+00:00 app[web.1]: /app/vendor/bundle/ruby/3.0.0/gems/mailgun-ruby-1.2.4/lib/railgun/mailer.rb:51:in `deliver!'
2022-09-06T21:13:58.303375+00:00 app[web.1]: /app/vendor/bundle/ruby/3.0.0/gems/mail-2.7.1/lib/mail/message.rb:2159:in `do_delivery'
2022-09-06T21:13:58.303376+00:00 app[web.1]: /app/vendor/bundle/ruby/3.0.0/gems/mail-2.7.1/lib/mail/message.rb:260:in `block in deliver'
2022-09-06T21:13:58.303376+00:00 app[web.1]: /app/vendor/bundle/ruby/3.0.0/gems/actionmailer-6.1.5/lib/action_mailer/base.rb:559:in `block in deliver_mail'
2022-09-06T21:13:58.303377+00:00 app[web.1]: /app/vendor/bundle/ruby/3.0.0/gems/activesupport-6.1.5/lib/active_support/notifications.rb:203:in `block in instrument'
2022-09-06T21:13:58.303377+00:00 app[web.1]: /app/vendor/bundle/ruby/3.0.0/gems/activesupport-6.1.5/lib/active_support/notifications/instrumenter.rb:24:in `instrument'
2022-09-06T21:13:58.303378+00:00 app[web.1]: /app/vendor/bundle/ruby/3.0.0/gems/activesupport-6.1.5/lib/active_support/notifications.rb:203:in `instrument'
2022-09-06T21:13:58.303378+00:00 app[web.1]: /app/vendor/bundle/ruby/3.0.0/gems/actionmailer-6.1.5/lib/action_mailer/base.rb:557:in `deliver_mail'
2022-09-06T21:13:58.303378+00:00 app[web.1]: /app/vendor/bundle/ruby/3.0.0/gems/mail-2.7.1/lib/mail/message.rb:260:in `deliver'
2022-09-06T21:13:58.303378+00:00 app[web.1]: /app/vendor/bundle/ruby/3.0.0/gems/actionmailer-6.1.5/lib/action_mailer/message_delivery.rb:119:in `block in deliver_now'
2022-09-06T21:13:58.303379+00:00 app[web.1]: /app/vendor/bundle/ruby/3.0.0/gems/actionmailer-6.1.5/lib/action_mailer/rescuable.rb:17:in `handle_exceptions'
2022-09-06T21:13:58.303379+00:00 app[web.1]: /app/vendor/bundle/ruby/3.0.0/gems/actionmailer-6.1.5/lib/action_mailer/message_delivery.rb:118:in `deliver_now'
2022-09-06T21:13:58.303379+00:00 app[web.1]: /app/vendor/bundle/ruby/3.0.0/gems/exception_notification-4.5.0/lib/exception_notifier/email_notifier.rb:171:in `call'
2022-09-06T21:13:58.303380+00:00 app[web.1]: /app/app/services/exception_notifier/violet_rails_error_notifier.rb:16:in `call'
2022-09-06T21:13:58.303380+00:00 app[web.1]: /app/vendor/bundle/ruby/3.0.0/gems/exception_notification-4.5.0/lib/exception_notifier.rb:161:in `fire_notification'
2022-09-06T21:13:58.303381+00:00 app[web.1]: /app/vendor/bundle/ruby/3.0.0/gems/exception_notification-4.5.0/lib/exception_notifier.rb:70:in `block in notify_exception'
2022-09-06T21:13:58.303381+00:00 app[web.1]: /app/vendor/bundle/ruby/3.0.0/gems/exception_notification-4.5.0/lib/exception_notifier.rb:68:in `each'
2022-09-06T21:13:58.303381+00:00 app[web.1]: /app/vendor/bundle/ruby/3.0.0/gems/exception_notification-4.5.0/lib/exception_notifier.rb:68:in `notify_exception'
2022-09-06T21:13:58.303381+00:00 app[web.1]: /app/vendor/bundle/ruby/3.0.0/gems/exception_notification-4.5.0/lib/exception_notification/rack.rb:59:in `rescue in call'
2022-09-06T21:13:58.303382+00:00 app[web.1]: /app/vendor/bundle/ruby/3.0.0/gems/exception_notification-4.5.0/lib/exception_notification/rack.rb:48:in `call'
2022-09-06T21:13:58.303382+00:00 app[web.1]: /app/vendor/bundle/ruby/3.0.0/gems/warden-1.2.9/lib/warden/manager.rb:36:in `block in call'
2022-09-06T21:13:58.303382+00:00 app[web.1]: /app/vendor/bundle/ruby/3.0.0/gems/warden-1.2.9/lib/warden/manager.rb:34:in `catch'
2022-09-06T21:13:58.303382+00:00 app[web.1]: /app/vendor/bundle/ruby/3.0.0/gems/warden-1.2.9/lib/warden/manager.rb:34:in `call'
2022-09-06T21:13:58.303383+00:00 app[web.1]: /app/vendor/bundle/ruby/3.0.0/gems/rack-2.2.3.1/lib/rack/tempfile_reaper.rb:15:in `call'
2022-09-06T21:13:58.303384+00:00 app[web.1]: /app/vendor/bundle/ruby/3.0.0/gems/rack-2.2.3.1/lib/rack/etag.rb:27:in `call'
2022-09-06T21:13:58.303384+00:00 app[web.1]: /app/vendor/bundle/ruby/3.0.0/gems/rack-2.2.3.1/lib/rack/conditional_get.rb:27:in `call'
2022-09-06T21:13:58.303384+00:00 app[web.1]: /app/vendor/bundle/ruby/3.0.0/gems/rack-2.2.3.1/lib/rack/head.rb:12:in `call'
2022-09-06T21:13:58.303385+00:00 app[web.1]: /app/vendor/bundle/ruby/3.0.0/gems/actionpack-6.1.5/lib/action_dispatch/http/permissions_policy.rb:22:in `call'
2022-09-06T21:13:58.303385+00:00 app[web.1]: /app/vendor/bundle/ruby/3.0.0/gems/actionpack-6.1.5/lib/action_dispatch/http/content_security_policy.rb:19:in `call'
2022-09-06T21:13:58.303385+00:00 app[web.1]: /app/vendor/bundle/ruby/3.0.0/gems/rack-2.2.3.1/lib/rack/session/abstract/id.rb:266:in `context'
2022-09-06T21:13:58.303386+00:00 app[web.1]: /app/vendor/bundle/ruby/3.0.0/gems/rack-2.2.3.1/lib/rack/session/abstract/id.rb:260:in `call'
2022-09-06T21:13:58.303386+00:00 app[web.1]: /app/vendor/bundle/ruby/3.0.0/gems/actionpack-6.1.5/lib/action_dispatch/middleware/cookies.rb:689:in `call'
2022-09-06T21:13:58.303386+00:00 app[web.1]: /app/vendor/bundle/ruby/3.0.0/gems/actionpack-6.1.5/lib/action_dispatch/middleware/callbacks.rb:27:in `block in call'
2022-09-06T21:13:58.303387+00:00 app[web.1]: /app/vendor/bundle/ruby/3.0.0/gems/activesupport-6.1.5/lib/active_support/callbacks.rb:98:in `run_callbacks'
2022-09-06T21:13:58.303390+00:00 app[web.1]: /app/vendor/bundle/ruby/3.0.0/gems/actionpack-6.1.5/lib/action_dispatch/middleware/callbacks.rb:26:in `call'
2022-09-06T21:13:58.303391+00:00 app[web.1]: /app/vendor/bundle/ruby/3.0.0/gems/actionpack-6.1.5/lib/action_dispatch/middleware/actionable_exceptions.rb:18:in `call'
2022-09-06T21:13:58.303391+00:00 app[web.1]: /app/vendor/bundle/ruby/3.0.0/gems/actionpack-6.1.5/lib/action_dispatch/middleware/debug_exceptions.rb:29:in `call'
2022-09-06T21:13:58.303391+00:00 app[web.1]: /app/vendor/bundle/ruby/3.0.0/gems/web-console-4.1.0/lib/web_console/middleware.rb:132:in `call_app'
2022-09-06T21:13:58.303392+00:00 app[web.1]: /app/vendor/bundle/ruby/3.0.0/gems/web-console-4.1.0/lib/web_console/middleware.rb:28:in `block in call'
2022-09-06T21:13:58.303392+00:00 app[web.1]: /app/vendor/bundle/ruby/3.0.0/gems/web-console-4.1.0/lib/web_console/middleware.rb:17:in `catch'
2022-09-06T21:13:58.303392+00:00 app[web.1]: /app/vendor/bundle/ruby/3.0.0/gems/web-console-4.1.0/lib/web_console/middleware.rb:17:in `call'
2022-09-06T21:13:58.303393+00:00 app[web.1]: /app/vendor/bundle/ruby/3.0.0/gems/actionpack-6.1.5/lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
2022-09-06T21:13:58.303393+00:00 app[web.1]: /app/vendor/bundle/ruby/3.0.0/gems/railties-6.1.5/lib/rails/rack/logger.rb:37:in `call_app'
2022-09-06T21:13:58.303393+00:00 app[web.1]: /app/vendor/bundle/ruby/3.0.0/gems/railties-6.1.5/lib/rails/rack/logger.rb:26:in `block in call'
2022-09-06T21:13:58.303394+00:00 app[web.1]: /app/vendor/bundle/ruby/3.0.0/gems/activesupport-6.1.5/lib/active_support/tagged_logging.rb:99:in `block in tagged'
2022-09-06T21:13:58.303394+00:00 app[web.1]: /app/vendor/bundle/ruby/3.0.0/gems/activesupport-6.1.5/lib/active_support/tagged_logging.rb:37:in `tagged'
2022-09-06T21:13:58.303394+00:00 app[web.1]: /app/vendor/bundle/ruby/3.0.0/gems/activesupport-6.1.5/lib/active_support/tagged_logging.rb:99:in `tagged'
2022-09-06T21:13:58.303395+00:00 app[web.1]: /app/vendor/bundle/ruby/3.0.0/gems/railties-6.1.5/lib/rails/rack/logger.rb:26:in `call'
2022-09-06T21:13:58.303395+00:00 app[web.1]: /app/vendor/bundle/ruby/3.0.0/gems/ahoy_matey-3.2.0/lib/ahoy/engine.rb:22:in `call_with_quiet_ahoy'
2022-09-06T21:13:58.303395+00:00 app[web.1]: /app/vendor/bundle/ruby/3.0.0/gems/actionpack-6.1.5/lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
2022-09-06T21:13:58.303395+00:00 app[web.1]: /app/vendor/bundle/ruby/3.0.0/gems/actionpack-6.1.5/lib/action_dispatch/middleware/request_id.rb:26:in `call'
2022-09-06T21:13:58.303396+00:00 app[web.1]: /app/vendor/bundle/ruby/3.0.0/gems/rack-2.2.3.1/lib/rack/method_override.rb:24:in `call'
2022-09-06T21:13:58.303396+00:00 app[web.1]: /app/vendor/bundle/ruby/3.0.0/gems/rack-2.2.3.1/lib/rack/runtime.rb:22:in `call'
2022-09-06T21:13:58.303397+00:00 app[web.1]: /app/vendor/bundle/ruby/3.0.0/gems/activesupport-6.1.5/lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
2022-09-06T21:13:58.303397+00:00 app[web.1]: /app/vendor/bundle/ruby/3.0.0/gems/actionpack-6.1.5/lib/action_dispatch/middleware/executor.rb:14:in `call'
2022-09-06T21:13:58.303397+00:00 app[web.1]: /app/vendor/bundle/ruby/3.0.0/gems/actionpack-6.1.5/lib/action_dispatch/middleware/static.rb:24:in `call'
2022-09-06T21:13:58.303398+00:00 app[web.1]: /app/vendor/bundle/ruby/3.0.0/gems/rack-2.2.3.1/lib/rack/sendfile.rb:110:in `call'
2022-09-06T21:13:58.303398+00:00 app[web.1]: /app/vendor/bundle/ruby/3.0.0/gems/actionpack-6.1.5/lib/action_dispatch/middleware/host_authorization.rb:142:in `call'
2022-09-06T21:13:58.303398+00:00 app[web.1]: /app/vendor/bundle/ruby/3.0.0/gems/rack-cors-1.1.1/lib/rack/cors.rb:100:in `call'
2022-09-06T21:13:58.303399+00:00 app[web.1]: /app/vendor/bundle/ruby/3.0.0/gems/railties-6.1.5/lib/rails/engine.rb:539:in `call'
2022-09-06T21:13:58.303399+00:00 app[web.1]: /app/vendor/bundle/ruby/3.0.0/gems/puma-5.6.4/lib/puma/configuration.rb:252:in `call'
2022-09-06T21:13:58.303399+00:00 app[web.1]: /app/vendor/bundle/ruby/3.0.0/gems/puma-5.6.4/lib/puma/request.rb:77:in `block in handle_request'
2022-09-06T21:13:58.303400+00:00 app[web.1]: /app/vendor/bundle/ruby/3.0.0/gems/puma-5.6.4/lib/puma/thread_pool.rb:340:in `with_force_shutdown'
2022-09-06T21:13:58.303400+00:00 app[web.1]: /app/vendor/bundle/ruby/3.0.0/gems/puma-5.6.4/lib/puma/request.rb:76:in `handle_request'
2022-09-06T21:13:58.303400+00:00 app[web.1]: /app/vendor/bundle/ruby/3.0.0/gems/puma-5.6.4/lib/puma/server.rb:441:in `process_client'
2022-09-06T21:13:58.303400+00:00 app[web.1]: /app/vendor/bundle/ruby/3.0.0/gems/puma-5.6.4/lib/puma/thread_pool.rb:147:in `block in spawn_thread'
2022-09-06T21:13:58.305736+00:00 app[web.1]: F, [2022-09-06T21:13:58.305166 #12] FATAL -- : [52ea5fcb-2ef3-4156-91e8-051229210180]
2022-09-06T21:13:58.305740+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] ActionView::Template::Error (undefined method `api_namespace_resource' for #<ActionView::Base:0x000000000460c8>
2022-09-06T21:13:58.305742+00:00 app[web.1]: Did you mean? api_namespace_resource_url
2022-09-06T21:13:58.305742+00:00 app[web.1]: api_namespace_resources_url
2022-09-06T21:13:58.305743+00:00 app[web.1]: api_namespace_resource_path
2022-09-06T21:13:58.305743+00:00 app[web.1]: api_namespace_resources_path
2022-09-06T21:13:58.305743+00:00 app[web.1]: api_namespace_url
2022-09-06T21:13:58.305744+00:00 app[web.1]: api_namespaces_url):
2022-09-06T21:13:58.305744+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] 37: </form>
2022-09-06T21:13:58.305745+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] 38: </div>
2022-09-06T21:13:58.305745+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] 39: </nav>
2022-09-06T21:13:58.305746+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] 40: <main><p><%= api_namespace_resource("cars-show") %>
2022-09-06T21:13:58.305746+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] 41: </p></main>
2022-09-06T21:13:58.305747+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180]
2022-09-06T21:13:58.305747+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] inline template:40
2022-09-06T21:13:58.305747+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] actionview (6.1.5) lib/action_view/base.rb:247:in `public_send'
2022-09-06T21:13:58.305748+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] actionview (6.1.5) lib/action_view/base.rb:247:in `_run'
2022-09-06T21:13:58.305748+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] actionview (6.1.5) lib/action_view/template.rb:154:in `block in render'
2022-09-06T21:13:58.305749+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] activesupport (6.1.5) lib/active_support/notifications.rb:205:in `instrument'
2022-09-06T21:13:58.305749+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] actionview (6.1.5) lib/action_view/template.rb:345:in `instrument_render_template'
2022-09-06T21:13:58.305749+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] actionview (6.1.5) lib/action_view/template.rb:152:in `render'
2022-09-06T21:13:58.305750+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] actionview (6.1.5) lib/action_view/renderer/template_renderer.rb:61:in `block (2 levels) in render_template'
2022-09-06T21:13:58.305750+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] activesupport (6.1.5) lib/active_support/notifications.rb:203:in `block in instrument'
2022-09-06T21:13:58.305750+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] activesupport (6.1.5) lib/active_support/notifications/instrumenter.rb:24:in `instrument'
2022-09-06T21:13:58.305751+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] activesupport (6.1.5) lib/active_support/notifications.rb:203:in `instrument'
2022-09-06T21:13:58.305751+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] actionview (6.1.5) lib/action_view/renderer/template_renderer.rb:56:in `block in render_template'
2022-09-06T21:13:58.305752+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] actionview (6.1.5) lib/action_view/renderer/template_renderer.rb:71:in `block in render_with_layout'
2022-09-06T21:13:58.305752+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] activesupport (6.1.5) lib/active_support/notifications.rb:203:in `block in instrument'
2022-09-06T21:13:58.305753+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] activesupport (6.1.5) lib/active_support/notifications/instrumenter.rb:24:in `instrument'
2022-09-06T21:13:58.305753+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] activesupport (6.1.5) lib/active_support/notifications.rb:203:in `instrument'
2022-09-06T21:13:58.305753+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] actionview (6.1.5) lib/action_view/renderer/template_renderer.rb:70:in `render_with_layout'
2022-09-06T21:13:58.305753+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] actionview (6.1.5) lib/action_view/renderer/template_renderer.rb:55:in `render_template'
2022-09-06T21:13:58.305754+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] actionview (6.1.5) lib/action_view/renderer/template_renderer.rb:11:in `render'
2022-09-06T21:13:58.305754+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] actionview (6.1.5) lib/action_view/renderer/renderer.rb:61:in `render_template_to_object'
2022-09-06T21:13:58.305754+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] actionview (6.1.5) lib/action_view/renderer/renderer.rb:29:in `render_to_object'
2022-09-06T21:13:58.305754+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] actionview (6.1.5) lib/action_view/rendering.rb:117:in `block in _render_template'
2022-09-06T21:13:58.305755+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] actionview (6.1.5) lib/action_view/base.rb:273:in `in_rendering_context'
2022-09-06T21:13:58.305755+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] actionview (6.1.5) lib/action_view/rendering.rb:116:in `_render_template'
2022-09-06T21:13:58.305755+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] actionpack (6.1.5) lib/action_controller/metal/streaming.rb:218:in `_render_template'
2022-09-06T21:13:58.305755+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] actionview (6.1.5) lib/action_view/rendering.rb:103:in `render_to_body'
2022-09-06T21:13:58.305756+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] actionpack (6.1.5) lib/action_controller/metal/rendering.rb:52:in `render_to_body'
2022-09-06T21:13:58.305761+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] actionpack (6.1.5) lib/action_controller/metal/renderers.rb:142:in `render_to_body'
2022-09-06T21:13:58.305761+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] actionpack (6.1.5) lib/abstract_controller/rendering.rb:25:in `render'
2022-09-06T21:13:58.305761+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] actionpack (6.1.5) lib/action_controller/metal/rendering.rb:36:in `render'
2022-09-06T21:13:58.305762+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] actionpack (6.1.5) lib/action_controller/metal/instrumentation.rb:46:in `block (2 levels) in render'
2022-09-06T21:13:58.305762+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] vendor/ruby-3.0.0/lib/ruby/3.0.0/benchmark.rb:308:in `realtime'
2022-09-06T21:13:58.305762+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] activesupport (6.1.5) lib/active_support/core_ext/benchmark.rb:14:in `ms'
2022-09-06T21:13:58.305763+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] actionpack (6.1.5) lib/action_controller/metal/instrumentation.rb:46:in `block in render'
2022-09-06T21:13:58.305763+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] actionpack (6.1.5) lib/action_controller/metal/instrumentation.rb:86:in `cleanup_view_runtime'
2022-09-06T21:13:58.305763+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] activerecord (6.1.5) lib/active_record/railties/controller_runtime.rb:34:in `cleanup_view_runtime'
2022-09-06T21:13:58.305764+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] actionpack (6.1.5) lib/action_controller/metal/instrumentation.rb:45:in `render'
2022-09-06T21:13:58.305764+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] comfortable-mexican-sofa (456fb8507e96) lib/comfortable_mexican_sofa/render_methods.rb:59:in `render'
2022-09-06T21:13:58.305764+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] meta-tags (2.14.0) lib/meta_tags/controller_helper.rb:22:in `render'
2022-09-06T21:13:58.305764+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] comfortable-mexican-sofa (456fb8507e96) app/controllers/comfy/cms/content_controller.rb:38:in `render_page'
2022-09-06T21:13:58.305765+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] comfortable-mexican-sofa (456fb8507e96) app/controllers/comfy/cms/content_controller.rb:22:in `block (2 levels) in show'
2022-09-06T21:13:58.305765+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] actionpack (6.1.5) lib/action_controller/metal/mime_responds.rb:214:in `respond_to'
2022-09-06T21:13:58.305765+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] comfortable-mexican-sofa (456fb8507e96) app/controllers/comfy/cms/content_controller.rb:21:in `show'
2022-09-06T21:13:58.305766+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] actionpack (6.1.5) lib/action_controller/metal/basic_implicit_render.rb:6:in `send_action'
2022-09-06T21:13:58.305766+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] actionpack (6.1.5) lib/abstract_controller/base.rb:228:in `process_action'
2022-09-06T21:13:58.305766+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] actionpack (6.1.5) lib/action_controller/metal/rendering.rb:30:in `process_action'
2022-09-06T21:13:58.305766+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] actionpack (6.1.5) lib/abstract_controller/callbacks.rb:42:in `block in process_action'
2022-09-06T21:13:58.305767+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] activesupport (6.1.5) lib/active_support/callbacks.rb:117:in `block in run_callbacks'
2022-09-06T21:13:58.305767+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] actiontext (6.1.5) lib/action_text/rendering.rb:20:in `with_renderer'
2022-09-06T21:13:58.305767+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] actiontext (6.1.5) lib/action_text/engine.rb:59:in `block (4 levels) in <class:Engine>'
2022-09-06T21:13:58.305767+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] activesupport (6.1.5) lib/active_support/callbacks.rb:126:in `instance_exec'
2022-09-06T21:13:58.305768+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] activesupport (6.1.5) lib/active_support/callbacks.rb:126:in `block in run_callbacks'
2022-09-06T21:13:58.305768+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] ahoy_matey (3.2.0) lib/ahoy/controller.rb:45:in `set_ahoy_request_store'
2022-09-06T21:13:58.305768+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] activesupport (6.1.5) lib/active_support/callbacks.rb:126:in `block in run_callbacks'
2022-09-06T21:13:58.305768+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] activesupport (6.1.5) lib/active_support/callbacks.rb:137:in `run_callbacks'
2022-09-06T21:13:58.305768+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] actionpack (6.1.5) lib/abstract_controller/callbacks.rb:41:in `process_action'
2022-09-06T21:13:58.305769+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] actionpack (6.1.5) lib/action_controller/metal/rescue.rb:22:in `process_action'
2022-09-06T21:13:58.305769+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] actionpack (6.1.5) lib/action_controller/metal/instrumentation.rb:34:in `block in process_action'
2022-09-06T21:13:58.305769+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] activesupport (6.1.5) lib/active_support/notifications.rb:203:in `block in instrument'
2022-09-06T21:13:58.305772+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] activesupport (6.1.5) lib/active_support/notifications/instrumenter.rb:24:in `instrument'
2022-09-06T21:13:58.305773+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] activesupport (6.1.5) lib/active_support/notifications.rb:203:in `instrument'
2022-09-06T21:13:58.305773+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] actionpack (6.1.5) lib/action_controller/metal/instrumentation.rb:33:in `process_action'
2022-09-06T21:13:58.305773+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] actionpack (6.1.5) lib/action_controller/metal/params_wrapper.rb:249:in `process_action'
2022-09-06T21:13:58.305773+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] activerecord (6.1.5) lib/active_record/railties/controller_runtime.rb:27:in `process_action'
2022-09-06T21:13:58.305774+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] actionpack (6.1.5) lib/abstract_controller/base.rb:165:in `process'
2022-09-06T21:13:58.305774+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] actionview (6.1.5) lib/action_view/rendering.rb:39:in `process'
2022-09-06T21:13:58.305774+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] actionpack (6.1.5) lib/action_controller/metal.rb:190:in `dispatch'
2022-09-06T21:13:58.305775+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] actionpack (6.1.5) lib/action_controller/metal.rb:254:in `dispatch'
2022-09-06T21:13:58.305775+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] actionpack (6.1.5) lib/action_dispatch/routing/route_set.rb:50:in `dispatch'
2022-09-06T21:13:58.305776+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] actionpack (6.1.5) lib/action_dispatch/routing/route_set.rb:33:in `serve'
2022-09-06T21:13:58.305776+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] actionpack (6.1.5) lib/action_dispatch/journey/router.rb:50:in `block in serve'
2022-09-06T21:13:58.305777+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] actionpack (6.1.5) lib/action_dispatch/journey/router.rb:32:in `each'
2022-09-06T21:13:58.305777+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] actionpack (6.1.5) lib/action_dispatch/journey/router.rb:32:in `serve'
2022-09-06T21:13:58.305778+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] actionpack (6.1.5) lib/action_dispatch/routing/route_set.rb:842:in `call'
2022-09-06T21:13:58.305778+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] turnout (2.5.0) lib/rack/turnout.rb:25:in `call'
2022-09-06T21:13:58.305778+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] ros-apartment (2.9.0) lib/apartment/elevators/generic.rb:22:in `block in call'
2022-09-06T21:13:58.305779+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] ros-apartment (2.9.0) lib/apartment/adapters/abstract_adapter.rb:89:in `switch'
2022-09-06T21:13:58.305779+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] vendor/ruby-3.0.0/lib/ruby/3.0.0/forwardable.rb:238:in `switch'
2022-09-06T21:13:58.305779+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] ros-apartment (2.9.0) lib/apartment/elevators/generic.rb:22:in `call'
2022-09-06T21:13:58.305780+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] exception_notification (4.5.0) lib/exception_notification/rack.rb:49:in `call'
2022-09-06T21:13:58.305780+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] warden (1.2.9) lib/warden/manager.rb:36:in `block in call'
2022-09-06T21:13:58.305780+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] warden (1.2.9) lib/warden/manager.rb:34:in `catch'
2022-09-06T21:13:58.305781+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] warden (1.2.9) lib/warden/manager.rb:34:in `call'
2022-09-06T21:13:58.305781+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] rack (2.2.3.1) lib/rack/tempfile_reaper.rb:15:in `call'
2022-09-06T21:13:58.305781+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] rack (2.2.3.1) lib/rack/etag.rb:27:in `call'
2022-09-06T21:13:58.305782+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] rack (2.2.3.1) lib/rack/conditional_get.rb:27:in `call'
2022-09-06T21:13:58.305782+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] rack (2.2.3.1) lib/rack/head.rb:12:in `call'
2022-09-06T21:13:58.305782+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] actionpack (6.1.5) lib/action_dispatch/http/permissions_policy.rb:22:in `call'
2022-09-06T21:13:58.305782+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] actionpack (6.1.5) lib/action_dispatch/http/content_security_policy.rb:19:in `call'
2022-09-06T21:13:58.305782+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] rack (2.2.3.1) lib/rack/session/abstract/id.rb:266:in `context'
2022-09-06T21:13:58.305783+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] rack (2.2.3.1) lib/rack/session/abstract/id.rb:260:in `call'
2022-09-06T21:13:58.305783+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] actionpack (6.1.5) lib/action_dispatch/middleware/cookies.rb:689:in `call'
2022-09-06T21:13:58.305783+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] actionpack (6.1.5) lib/action_dispatch/middleware/callbacks.rb:27:in `block in call'
2022-09-06T21:13:58.305784+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] activesupport (6.1.5) lib/active_support/callbacks.rb:98:in `run_callbacks'
2022-09-06T21:13:58.305784+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] actionpack (6.1.5) lib/action_dispatch/middleware/callbacks.rb:26:in `call'
2022-09-06T21:13:58.305784+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] actionpack (6.1.5) lib/action_dispatch/middleware/actionable_exceptions.rb:18:in `call'
2022-09-06T21:13:58.305787+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] actionpack (6.1.5) lib/action_dispatch/middleware/debug_exceptions.rb:29:in `call'
2022-09-06T21:13:58.305788+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] web-console (4.1.0) lib/web_console/middleware.rb:132:in `call_app'
2022-09-06T21:13:58.305788+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] web-console (4.1.0) lib/web_console/middleware.rb:28:in `block in call'
2022-09-06T21:13:58.305795+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] web-console (4.1.0) lib/web_console/middleware.rb:17:in `catch'
2022-09-06T21:13:58.305795+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] web-console (4.1.0) lib/web_console/middleware.rb:17:in `call'
2022-09-06T21:13:58.305795+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] actionpack (6.1.5) lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
2022-09-06T21:13:58.305795+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] railties (6.1.5) lib/rails/rack/logger.rb:37:in `call_app'
2022-09-06T21:13:58.305796+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] railties (6.1.5) lib/rails/rack/logger.rb:26:in `block in call'
2022-09-06T21:13:58.305796+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] activesupport (6.1.5) lib/active_support/tagged_logging.rb:99:in `block in tagged'
2022-09-06T21:13:58.305796+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] activesupport (6.1.5) lib/active_support/tagged_logging.rb:37:in `tagged'
2022-09-06T21:13:58.305797+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] activesupport (6.1.5) lib/active_support/tagged_logging.rb:99:in `tagged'
2022-09-06T21:13:58.305797+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] railties (6.1.5) lib/rails/rack/logger.rb:26:in `call'
2022-09-06T21:13:58.305797+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] ahoy_matey (3.2.0) lib/ahoy/engine.rb:22:in `call_with_quiet_ahoy'
2022-09-06T21:13:58.305797+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] actionpack (6.1.5) lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
2022-09-06T21:13:58.305798+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] actionpack (6.1.5) lib/action_dispatch/middleware/request_id.rb:26:in `call'
2022-09-06T21:13:58.305798+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] rack (2.2.3.1) lib/rack/method_override.rb:24:in `call'
2022-09-06T21:13:58.305799+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] rack (2.2.3.1) lib/rack/runtime.rb:22:in `call'
2022-09-06T21:13:58.305799+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] activesupport (6.1.5) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
2022-09-06T21:13:58.305799+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] actionpack (6.1.5) lib/action_dispatch/middleware/executor.rb:14:in `call'
2022-09-06T21:13:58.305800+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] actionpack (6.1.5) lib/action_dispatch/middleware/static.rb:24:in `call'
2022-09-06T21:13:58.305800+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] rack (2.2.3.1) lib/rack/sendfile.rb:110:in `call'
2022-09-06T21:13:58.305800+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] actionpack (6.1.5) lib/action_dispatch/middleware/host_authorization.rb:142:in `call'
2022-09-06T21:13:58.305801+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] rack-cors (1.1.1) lib/rack/cors.rb:100:in `call'
2022-09-06T21:13:58.305801+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] railties (6.1.5) lib/rails/engine.rb:539:in `call'
2022-09-06T21:13:58.305801+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] puma (5.6.4) lib/puma/configuration.rb:252:in `call'
2022-09-06T21:13:58.305801+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] puma (5.6.4) lib/puma/request.rb:77:in `block in handle_request'
2022-09-06T21:13:58.305802+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] puma (5.6.4) lib/puma/thread_pool.rb:340:in `with_force_shutdown'
2022-09-06T21:13:58.305802+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] puma (5.6.4) lib/puma/request.rb:76:in `handle_request'
2022-09-06T21:13:58.305802+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] puma (5.6.4) lib/puma/server.rb:441:in `process_client'
2022-09-06T21:13:58.305802+00:00 app[web.1]: [52ea5fcb-2ef3-4156-91e8-051229210180] puma (5.6.4) lib/puma/thread_pool.rb:147:in `block in spawn_thread'
2022-09-06T21:13:58.306940+00:00 heroku[router]: at=info method=GET path="/nikean-test-details-page?id=463" host=violetrails.herokuapp.com request_id=52ea5fcb-2ef3-4156-91e8-051229210180 fwd="209.195.112.4" dyno=web.1 connect=0ms service=136ms status=500 bytes=4090 protocol=https
2
The above error happened because I didn't pass the correct identifier when calling render_api_namespace_resource. The demo app has an API namespace cars and I created a details page for each cars resource.
Snippet for details page
Markup of details page
Wrong:
<main>
{{ cms:helper render_api_namespace_resource 'cars-show' }}
</main>
Correct:
<main>
{{ cms:helper render_api_namespace_resource 'cars' }}
</main>
After looking at one of the test cases, I thought that I would have to specify the api namespace and append -show to it. I think the documentation will be clearer if we show a snippet of calling render_api_namespace_resource with the correct arguments.
{{ cms:helper render_api_namespace_resource 'cars' }}
Issue: Predefined sort order cannot be overridden later
if I initially render a list of resources like this:
# initially, the API resources of cars will be sorted from newest to oldest
{{ cms:helper render_api_namespace_resource_index 'cars', order: { created_at: 'DESC' } }}
I can't change the sort order of API resources through a select dropdown later. They are always sorted in descending order.
Index example:
Basic
{{ cms:helper render_api_namespace_resource_index 'cars' }}
WIth scope
{{ cms:helper render_api_namespace_resource_index 'cars', scope: { properties: { published: 'true' } } }}
Current user scope(only list records created by current user )
{{ cms:helper render_api_namespace_resource_index 'cars', scope: { current_user: 'true' } }}
With scope and order
{{ cms:helper render_api_namespace_resource_index 'cars', scope: { properties: { published: 'true' } }, order: { created_at: 'DESC' } }}
note: scope and order are in same level
Sorting by nested proprerties
{{ cms:helper render_api_namespace_resource_index 'cars', order: { properties: { name: 'DESC' } } }}
Sorting by multiple proprerties
{{ cms:helper render_api_namespace_resource_index 'cars', order: { created_at: 'ASC', properties: { name: 'DESC' } } }}
Show example:
Basic
{{ cms:helper render_api_namespace_resource 'cars-show' }}
With scope (scope helps filter out pages you don't want users to access, eg. unpublished cars should should not have show page)
{{ cms:helper render_api_namespace_resource 'cars-show', scope: { properties: { published: 'true' } } }}
Issue: Predefined sort order cannot be overridden later
@Ayon95 , Thanks for finding out the bug. I have fixed the issue. Please give it another round of testing.
@Pralish Thanks. Predefined sort order can be changed now. By the way, in the Show example, shouldn't it be cars instead of cars-show?
UAT result
- API resources can be searched based on a property value
- API resources can be filtered based on multiple properties (multiple filters can be applied)
- API resources can be sorted by date
- A show/details page of an API resource can be created including a list of similar API resources (recommendations list)
For the recommendations list, I compared the value of a property of the show API resource and all the other API resources.
<% @api_namespace.api_resources.reject {|resource| (Array.wrap(resource.properties['tags']) & Array.wrap(@api_resource.properties['tags'])).empty? || resource.id == @api_resource.id }.each do |resource| %>
tags is an array of tags, e.g. ["tesla", "electric"]. For a car X with tags = ["tesla", "electric"], the recommended cars need to have at least one of the tags of car X.
@Pralish Can you provide an example of how to render an image or video associated with an API resource? Thanks.
<% @api_resources.each do |resource| %>
<img src="image url here">
<video>
<source src="video url here">
</video>
<% end %>
@Ayon95 you will have to do something like this: https://github.com/restarone/violet_rails/blob/master/app/views/comfy/admin/api_namespaces/export_api_resources.csv.haml#L27
But we can't call subdomain inside a snippet because of safe execution. We will need this change that creates an API for safely accessing the subdomain to be included: https://github.com/restarone/violet_rails/pull/1082/files#diff-4c11ce7a17fb3d29da949ec1e1b5ae260b095d0cc3e2dcd1f6693443b1f59b08
@Pralish can you take the change above, include my feedback and add it to this branch for Mushfiq to use?
Latest change as per feedback: https://github.com/restarone/violet_rails/pull/1082/files#diff-32c6f34bca03f9cd85de752b7178c75d3a4d04559aaa21142da613fdda6b12f6
@donrestarone , Users will now be able to access non primitive properties through label:
https://github.com/restarone/violet_rails/pull/1047/commits/ad8452d1e165856614301db5a5329614c088da39
I have added a props method that we can use to access both primitive and non-primitive properties
eg:
primitive properties
api_resource.props['name']
or
current implementation works as well for primitive types
api_resource.properties['name']
file type
api_resource.props['image'].file_url
rich text
api_resource.props['text'].content
CC: @Ayon95
I noticed querying / filters / ordering is done with HTTP requests, is there a reason why we aren't using turbo? Everywhere else turbo is working
https://user-images.githubusercontent.com/35935196/190024048-5cc4d09d-bbaa-4b54-a296-11d7ac9226e5.mov
It's because just changing the query string in the URL won't update the list of resources.
@Pralish Is it possible to filter based on array values? Suppose every API resource has a property tags: ["tag1", "tag2", "tag3"]. If a user selects tag1 and tag2 (assume that there's a form that can be used to select tags), I want to show them API resources whose tags array contains at least one of the selected tags.
@Pralish Is it possible to limit the number of API resources that are rendered?
@Pralish Is it possible to limit the number of API resources that are rendered?
@Ayon95 , Do you want to do pagination, or just limit the resources?
We do not support pagination yet, however if you want to limit the resources, you can do something like this on index snippet.
<% @api_resources.limit(10).each do |resource| %>
Not pagination. I have to show some resources in a Bootstrap carousel. In the future, there will be many resources, so all of them can't be shown in a carousel. I can't set the limit in the index snippet because then the number of resources rendered will be limited in all other places, not just the carousels.
Can something like this be done?
# Where this helper will be called, at most 10 published resources will be rendered
{{ cms:helper render_api_namespace_resource_index 'slug', scope: { properties: { published: 'true' } }, limit: 10 }}
Also, I'm looking for a way to filter API resources by tags. There can be two options - loose and strict filtering. Suppose there is a movie namespace whose shape includes a tags property. tags will be an array, e.g. ["action", "comedy", "superhero"]. It can be like how a search query is made but instead of comparing a string, it will compare an array of strings.
Include any resources that have at least one of the specified tags (loose filtering)
{{ cms:helper render_api_namespace_resource_index 'slug', scope: { properties: { tags: { value: ['action', 'comedy', 'superhero'], option: 'ANY' } } } }}
Include only those resources that have all of the specified tags (strict filtering)
{{ cms:helper render_api_namespace_resource_index 'slug', scope: { properties: { tags: { value: ['action', 'comedy', 'superhero'], option: 'ALL' } } } }}
Noticed a bit of discrepancy with the two provided examples of sorting. Sorting doesn't work if order is placed inside scope.
This doesn't seem to work
{{ cms:helper render_api_namespace_resource_index 'cars', scope: { properties: { published: 'true' }, order: { created_at: 'DESC' } } }}
This works
{{ cms:helper render_api_namespace_resource_index 'cars', scope: { properties: { published: 'true' } }, order: { created_at: 'DESC' } }}
It'll be a good idea to get rid of the inaccurate example.
@Pralish Is it possible to tell the renderer to ignore the query string for a particular call to render_api_namespace_resource_index? In certain cases, I don't want the query string to override the initial scope and conditions.
Suppose, I have the following snippets initially in the HTML:
{{ cms:helper render_api_namespace_resource_index 'one', allow_override: false }}
{{ cms:helper render_api_namespace_resource_index 'two', order: { created_at: 'DESC' } }}
Later on, if a query string is added to the URL, it should not be applied to one because overriding is not allowed. The query string should be applied to two since overriding is allowed for it.
Perhaps the renderer can accept a boolean property like allow_override. By default, overriding will be allowed (allow_override will be set to true).