lundi 13 avril 2015

Convert string of table name type in rails [duplicate]


This question already has an answer here:




I am looping through all the table names in database and printing them with their data. But, I want to know how can I convert a variable name which stores table name to actual table type i.e. it can be considered as a table instead of a string. Here is a example:



<% ActiveRecord::Base.connection.tables.each do |table| %>
<% table.column_names.each do |column| %>
<%= column %>
<% end %>


Here table becomes a variable but its value is actual table name obtained from database. I am trying to do the rails db command, for eg:



> User.column_names

Aucun commentaire:

Enregistrer un commentaire