Skip to content

Instantly share code, notes, and snippets.

@ugisozols
Created November 11, 2017 21:35
Show Gist options
  • Save ugisozols/98ff736514cc0edf4e2d25ffc1c6a257 to your computer and use it in GitHub Desktop.
Save ugisozols/98ff736514cc0edf4e2d25ffc1c6a257 to your computer and use it in GitHub Desktop.
no argument named 'user_names'
# src/pages/base_page.cr
abstract class BasePage
include LuckyWeb::HTMLPage
def render
html lang: "en" do
head do
utf8_charset
title page_title
css_link asset("css/app.css")
js_link asset("js/app.js")
end
body do
inner
end
end
end
abstract def inner
def page_title
"Default title"
end
end
# src/pages/users/index_page.cr
class Users::IndexPage < BasePage
needs user_names : Array(String)
def inner
ul class: "my-user-list" do
@user_names.each do |name|
li name, class: "user-name"
end
end
end
def page_title
"List of users"
end
end
# src/actions/users/index.cr
class Users::Index < BrowserAction
action do
render user_names: ["Paul", "Sally", "Jane"]
end
end
@ugisozols
Copy link
Author

Getting:

23:36:04 web.1      |     1.     def call : LuckyWeb::Response
23:36:04 web.1      |     2.       callback_result = run_before_callbacks
23:36:04 web.1      |     3.
23:36:04 web.1      |     4.       response = if callback_result.is_a?(LuckyWeb::Response)
23:36:04 web.1      |     5.         callback_result
23:36:04 web.1      |     6.       else
23:36:04 web.1      |  >  7.         render(user_names: ["Paul", "Sally", "Jane"])
23:36:04 web.1      |     8.       end
23:36:04 web.1      |     9.
23:36:04 web.1      |    10.       callback_result = run_after_callbacks
23:36:04 web.1      |    11.
23:36:04 web.1      |    12.       if callback_result.is_a?(LuckyWeb::Response)
23:36:04 web.1      |    13.         callback_result
23:36:04 web.1      |    14.       else
23:36:04 web.1      |    15.         response
23:36:04 web.1      |    16.       end
23:36:04 web.1      |    17.     end
23:36:04 web.1      |    18.
23:36:04 web.1      |  expanding macro
23:36:04 web.1      |  in macro 'render' /Users/ugisozols/sandbox/crystal/testy/lib/lucky_web/src/lucky_web/renderable.cr:16, line 1:
23:36:04 web.1      |  >  1.     view = Users::IndexPage.new(
23:36:04 web.1      |     2.
23:36:04 web.1      |     3.         user_names: ["Paul", "Sally", "Jane"],
23:36:04 web.1      |     4.
23:36:04 web.1      |     5.
23:36:04 web.1      |     6.     )
23:36:04 web.1      |     7.     log_html_render(context, view)
23:36:04 web.1      |     8.     body = view.render.to_s
23:36:04 web.1      |     9.     LuckyWeb::Response.new(context, "text/html", body)
23:36:04 web.1      |    10.
23:36:04 web.1      |  no argument named 'user_names'
23:36:04 web.1      |  Matches are:
23:36:04 web.1      |   - Reference.new()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment