Correct way to use nested link_to?

36 views Asked by At
<%= link_to controller: :personal_data, class:"px-6 py-4 flex items-center text-sm font-medium" do%>
    <span class="flex-shrink-0 w-10 h-10 flex items-center justify-center border-2 border-red-600 rounded-full">
       <span class="text-red-600">01</span>
    </span>
    <span class="ml-4 text-sm font-medium text-red-600">Personal Data</span>
<% end %>

The view seems to make it that the class attribute is a GET function. Here's the generated HTML

<a href="/personal_data?class=px-6+py-4+flex+items-center+text-sm+font-medium">
    <span class="flex-shrink-0 w-10 h-10 flex items-center justify-center border-2 border-red-600 rounded-full">
          <span class="text-red-600">01</span>
    </span>
    <span class="ml-4 text-sm font-medium text-red-600">Personal Data</span>
</a>

How should I write it so that the class would be working as it should be?

1

There are 1 answers

0
Vishal Jain On BEST ANSWER

You can set url using personal_data_path

<%= link_to personal_data_path, class:"px-6 py-4 flex items-center text-sm font-medium" do%>
    <span class="flex-shrink-0 w-10 h-10 flex items-center justify-center border-2 border-red-600 rounded-full">
       <span class="text-red-600">01</span>
    </span>
    <span class="ml-4 text-sm font-medium text-red-600">Personal Data</span>
<% end %>