Hola a todo necesito hacer un help_method que me entregue los datos de la tabla contact, ahora tengo esto en un archivo partial del layout que es la cabecera (head) de la web, que se carga según el rol del contacto y el tipo de user (que si es administrador del sitio o cliente del mismo), funciona perfectamente.
codigo:
<div class="headerSS">
<div class="navbar navbar-expand-sm navbar-light navbar-lewagon" >
<div class = "container-fluid">
<div class= "photo">
<% Client.find(user_id: current_user.id) do |user|%>
<%= image_tag user.logo, class:"imagen" %>
<%end%>
</div>
<button class="navbar-toggler text-white" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav me-auto">
<% if user_signed_in? %>
<%id = clientID(current_user.id).id%>
<% idcontact = HistContact.last%>
<% contactID = Contact.find_by(id: idcontact.contact_id)%>
<% if contactID.roles == "Administrador" %>
<li class="nav-item">
<%= link_to "Inicio", clients_home_path(), class: "nav-link text-white" %>
</li>
<li class="nav-item">
<%= link_to "Usuarios", client_contacts_path(id), class: "nav-link text-white" %>
</li>
<li class="nav-item">
<%= link_to "Reservas ", client_reservations_path(id), class: "nav-link text-white" %>
</li>
<li class="nav-item">
<%= link_to "Habitacion", client_rooms_path(id), class: "nav-link text-white" %>
</li>
<li class="nav-item dropdown lastDrop">
<%= link_to "Dinero", "#", class: "avatar dropdown-toggle nav-link text-white", id: "navbarDropdown", data: { bs_toggle: "dropdown" }, 'aria-haspopup': true, 'aria-expanded': false %>
<div class="dropdown-menu dropdown-menu-end" aria-labelledby="navbarDropdown">
<%= link_to "Cuenta Banco", client_client_currentaccounts_path(id), class: "dropdown-item" %>
<%#= link_to "Log out", destroy_user_session_path, method: :delete, class: "dropdown-item" %>
</div>
</li>
<li class="nav-item dropdown lastDrop">
<%= link_to "Politicas", "#", class: "avatar dropdown-toggle nav-link text-white", id: "navbarDropdown", data: { bs_toggle: "dropdown" }, 'aria-haspopup': true, 'aria-expanded': false %>
<div class="dropdown-menu dropdown-menu-end" aria-labelledby="navbarDropdown">
<%= link_to "Edad", client_age_policies_path(id), class: "dropdown-item" %>
<%= link_to "Devolucion", client_refund_policies_path(id), class: "dropdown-item" %>
<%= link_to "Cancelacion", client_cancel_policies_path(id), class: "dropdown-item" %>
<%= link_to "Cambio", client_change_policies_path(id), class: "dropdown-item" %>
<%#= link_to "Log out", destroy_user_session_path, method: :delete, class: "dropdown-item" %>
</div>
</li>
<li class="nav-item dropdown lastDrop">
<%= link_to "Historial", "#", class: "avatar dropdown-toggle nav-link text-white", id: "navbarDropdown", data: { bs_toggle: "dropdown" }, 'aria-haspopup': true, 'aria-expanded': false %>
<div class="dropdown-menu dropdown-menu-end" aria-labelledby="navbarDropdown">
<%= link_to "Empresa", hist_user_index_path, class: "dropdown-item" %>
<%= link_to "Funcionario", hist_contact_index_path, class: "dropdown-item" %>
</div>
</li>
<li>
<%= link_to "Log out", destroy_user_session_path, method: :delete, class: " nav-link text-white" %>
</li>
<% else %>
<li class="nav-item">
<%= link_to "Inicio", clients_home_path(), class: "nav-link text-white" %>
</li>
<li class="nav-item">
<%= link_to "Reservas ", client_reservations_path(id), class: "nav-link text-white" %>
</li>
<li class="nav-item">
<%= link_to "Habitacion", client_rooms_path(id), class: "nav-link text-white" %>
</li>
<li>
<%= link_to "Log out", destroy_user_session_path, method: :delete, class: " nav-link text-white" %>
</li>
<% end %>
<% else %>
<li class="nav-item">
<%= link_to "Login", new_user_session_path, class: "nav-link" %>
</li>
<% end %>
</ul>
</div>
</div>
</div>
</div>
<div class="container-fluid">
<div class="row">
<div class= "col-sm-6 col-md-6 text-end clientName">
<%Client.find(user_id: current_user.id) do |c| %>
<%= c.name%>
<%end%>
</div>
<div class= "col-sm-6 col-md-6 rigth-end clientUserClient" >
<!--<% Contact.find(user_id: current_user.id) do |ct|%>-->
<%= contactID.name%>
<%end%>
</div>
</div>
</div>
Tengo entendido que toda la lógica tiene que ir en los controladores.
hablo de estas lineas
<%id = clientID(current_user.id).id%>
<% idcontact = HistContact.last%>
<% contactID = Contact.find_by(id: idcontact.contact_id)%>
<% if contactID.roles == "Administrador" %>
Esta función es para determinar el rol y el id de cliente
La pregunta es como puedo hacerlo desde un controlador, ya que esto es un head dentro del layout, he pensado en hacer un helper_method, pero no me resulta.
Me pueden explicar como hacer el helper_method
Gracias