Skip to content

Instantly share code, notes, and snippets.

@wtnabe
Last active January 26, 2025 07:08
Show Gist options
  • Save wtnabe/7659c69522c871dfe4effcb0bea3956d to your computer and use it in GitHub Desktop.
Save wtnabe/7659c69522c871dfe4effcb0bea3956d to your computer and use it in GitHub Desktop.
dry-operation + dry-monads + ActiveModelほかいくつかの処理を交えていい具合にViewに返す試み
<% unless errors.empty? %>
エラーあります
<ul>
<% errors.each do |error| %>
<% # ActiveModel::ErrorsとDry::Schema::Message的なエラーをいい具合に扱う %>
<li><%= error.try(:attribute) || error.try(:path) %> : <%= error.try(:type) || error.try(:text) %></li>
<% end %>
</ul>
<% end %>
<% unless data.empty? %>
<a href="<%= data[:url] %>">&gt;&gt; next</a>
<% end %>
require "sinatra"
get "/" do
erb :new, locals: {anti_csrf_token: env["rack.session"][:csrf]}
end
post "/confirm" do
result = GenerateMagiclink.new.call(params["entry"])
erb: :confirm, locals: {
data: result.success? ? {url: result.value!} : {},
errors: result.failure? ? result.failure.errors: []
}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment