0

I am new to ruby on rails. The link_to controller is working fine with buttons but not sure how to call the controller from select options. Please advise.

<div>
  <table class="table">
    <tr>
      <th scope="col">Name </th>              
      <th scope="col">Email </th>                   
      <th scope="col">Disposition</th>
    </tr>
   
    <% @workspace.memberships_with_issues[:umich_guests].each do |guest| %>
      <% cache(guest) do %>
      <tr>
        <td scope="row"><%= guest.member.name %></td>
        <td scope="row"><%= guest.member.email %></td>
        <td scope="row">
          <select class="form-select"> 
            <option value="1" selected="selected">Undecided</option>
            <option value="2"><%= link_to 'Delete Member', workspace_member_disposition_path(@workspace.id, guest, "should_delete") %></option>
            <option value="3">Convert Guest to Full Member</option>
          </select>
        </td>
        <td><%= link_to 'Undecided', workspace_member_disposition_path(@workspace.id, guest, "undecided") %></td>
        <td><%= link_to 'Delete Member', workspace_member_disposition_path(@workspace.id, guest, "should_delete") %></td>
        <td><%= link_to 'Convert Guest to Full Member', workspace_member_disposition_path(@workspace.id, guest, "make_member") %></td>
      </tr>
      <% end %>
    <% end %>
  </table>
</div>
TKG
  • 1

1 Answers1

0

Turning a select input option into a link is not a good idea. Despite it is possible it goes againsy HTML semantics. You can find a way to do it in this answer:

https://stackoverflow.com/a/2000689/2908539

as well as an explanation of why it's not a good idea.

Maybe what you need is a drop down menu, it worths a little research about it.

  • I don't think `` is valid HTML at all, ` – mu is too short Sep 03 '21 at 04:14
  • I agree. I'd suggest just using links or - if you're up for it - using a Bootstrap button group: https://getbootstrap.com/docs/4.4/components/button-group/ – MSC Sep 03 '21 at 06:28
  • Please add further details to expand on your answer, such as working code or documentation citations. – Community Sep 03 '21 at 07:26