How to display to admin the specific data of each user chosen with Rails

Asked

Viewed 54 times

1

In the administrative part I’m doing my Admin can view all Subscriptions performed by users in a table (this part is working perfectly)

Code of my admin controller,

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 

Table image Tabela de lista de inscrições

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

  • The data you want to display in the modal, are all on the screen or you need to search from the database?

  • In the modal ta displaying just any html to do the front end. Some of the data are those of the table, but I will need to fetch others in the database

  • There are several ways to solve, but I do not know if the stack overflow will let it stay here, I think you better ask there in the google groups Rails-br.

1 answer

1

Faria via a native Rails Ajax request (Unobtrusive Javascript). http://guides.rubyonrails.org/working_with_javascript_in_rails.html

First you have to define what this modal will show, create in your Routes.Rb a call for your custom action

route.Rb

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

in the 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 must 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 to 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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.