How to display to admin the data specific to each user chosen with rails

1

In the administrative part that I'm doing, my Admin can see all Subscriptions made by users in a table (this part is working perfectly)

My admin controller's code,

def index
  @subs = Subscription.all
end

Table display code

table.table#table-admin
  thead
    tr
      th CPF
      th Cód
      th Endereço
      th Data
      th Tipo
      th Status
      th Do
  tbody
    - @subs.each do |subs|
      tr
        td = subs.user.cpf
        td = subs.realty.realty_code
        td = subs.realty.address.street + " , " + subs.realty.address.number
        td = subs.created_at.strftime("%d %b, %Y")
        td = subs.realty.listings.first.translated_listing_type
        td = subs.translated_status
        td
          button data-toggle="modal" data-target="#info" X 

Picture of the table

When I click the X button it calls a modal that should display the user information that it chose from the table, but I do not know how to specifically pass the information of each one.

    
asked by anonymous 18.04.2018 / 22:34

1 answer

1

It would do via a native Rails Ajax request (Unobtrusive JavaScript). link

First you have to define what this modal will show, create in your routes.rb a call to your custom action

route.rb

resources :subscription do
  get 'modal', on: :member
end

na view

tr
  td= link_to modal_subscription_path(subs), :class => 'btn btn-info', :title => t('show', :scope => 'helpers.links'), remote:true do

subscription_controller.rb

respond_to :html, :js

def modal
  respond_with Subscription.find(params[:id])
end

You should create a file

app / views / subscription / modal.js.erb

$('#responsive-modal .modal-content').html("<%= escape_javascript(render 'modal') %>");
$('#responsive-modal').modal('show');

create a file

app / views / subscription / _modal.html.slim

#Aqui coloque o html que você quer que apareça no modal

add on your

app / layouts / application.html.slim

#modal
  #responsive-modal.modal.fade aria-hidden="true" aria-labelledby="myModalLabel" role="dialog" style=("display: none;") tabindex="-1" 
   .modal-dialog
     .modal-content
    
01.05.2018 / 03:17