Files
ubicloud/views/dashboard.erb
Enes Cakir 65b2380521 Fix error raised when the user has no projects
I noticed several HTTP 500 responses in our web server logs, each
accompanied by the following exception:

    "NoMethodError: undefined method `path' for nil:NilClass"

We use @current_user.projects.first.path in two paths: /dashboard and
/after-login. If the user deletes all their projects, they can't access
these paths.

I resolved this issue by redirecting to different endpoints when the
user has no projects.
2023-11-23 16:30:21 +03:00

55 lines
2.3 KiB
Plaintext

<% @page_title = "Dashboard" %>
<div class="space-y-1">
<%== render("components/page_header", locals: { title: "Getting Started" }) %>
</div>
<div class="grid gap-6">
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4 md:gap-6 lg:gap-10">
<% [
if (project = @current_user.projects_dataset.order(:created_at).first)
[
"hero-server-stack", "bg-teal-50 text-teal-700", "Create Virtual Machine",
"Linux-based virtual machines that run on top of virtualized hardware. Comprehensive, cost-effective cloud computing.",
"#{project.path}/vm/create"
]
end, [
"hero-folder-open", "bg-purple-50 text-purple-700", "Create New Project",
"Projects are the central point for grouping resources and working with others within Ubicloud.",
"/project/create"
], [
"hero-cog-6-tooth", "bg-sky-50 text-sky-700", "My Account",
"Update your account details such as name, password.",
"/account"
], [
"hero-envelope", "bg-yellow-50 text-yellow-700", "Get Support",
"If you need any help with Ubicloud, reach out to our support team for help at support@ubicloud.com.",
"mailto:support@ubicloud.com"
]
].reject { !_1 }.each do |icon, color, title, description, link| %>
<div
class="rounded-lg shadow group relative bg-white p-6 focus-within:ring-2 focus-within:ring-inset focus-within:ring-orange-600"
>
<div>
<span class="inline-flex rounded-lg p-3 <%= color %> ring-4 ring-white">
<%== render("components/icon", locals: { name: icon }) %>
</span>
</div>
<div class="mt-8">
<h3 class="text-base font-semibold leading-6 text-gray-900">
<a href="<%= link %>" class="focus:outline-none">
<!-- Extend touch target to entire panel -->
<span class="absolute inset-0" aria-hidden="true"></span>
<%= title %>
</a>
</h3>
<p class="mt-2 text-sm text-gray-500"><%= description %></p>
</div>
<span class="pointer-events-none absolute right-6 top-6 text-gray-300 group-hover:text-gray-400">
<%== render("components/icon", locals: { name: "hero-arrow-up-right" }) %>
</span>
</div>
<% end %>
</div>
</div>