0

I am newbie on RoR. I have an array of columns and users like this :

@user_form_column_list = 
[#<MUserForm:0x0000560565e976c0
  user_form_id: 1401,
  site_id: 1071,
  filed_name: "Kana",
  db_column_name: "last_name",
  input_type: nil,
  input_rqrd: 1,
  order_num: 1,
  status_flg: 1>,
#<MUserForm:0x0000560565e976c0
  user_form_id: 1402,
  site_id: 1071,
  filed_name: "Kanaaa",
  db_column_name: "first_name",
  input_type: nil,
  input_rqrd: 1,
  order_num: 1,
  status_flg: 1>,...]
@users = 
[#<TUser:0x00007f107d74a6f0
  user_id: 11034,
  site_id: 1071,
  user_email: "[email protected]",
  last_name: nil,
  first_name: nil>,
#<TUser:0x00007f107d74a6f0
  user_id: 11035,
  site_id: 1071,
  user_email: "[email protected]",
  last_name: nil,
  first_name: nil>,...]

In views: index.html.erb:

<table border="0" cellpadding="0" cellspacing="0" class="table_top" width="100%">
  <tr>
    <th width="60">&nbsp;</th>
    <% @user_form_column_list.each do |column| %>
      <th><%= column.filed_name %></th>
    <% end %>
  </tr>
  <%= render "t_user" %>
</table>

_t_user.html.erb:

<% @users.each.with_index do |user. index| %>
<tr>
<td>
  <div align="center">
    <%= link_to "link" do %>
      <input type="button" value="編集">
    <% end %>
  </div>
</td>
<td nowrap="nowrap"><%=  %></td>
</tr>
<% end %>

So, My question: How to display the correct value with the corresponding fields in file _t_user.html.erb?

1
  • Hi, Your question is not clear. Please add more detail about what fields you want to show on the UI. Commented Aug 24, 2019 at 8:35

2 Answers 2

1

I'm not sure I understand your question, from your example input/output you can do something like:

TUser.pluck(:user_id, :name, :age)
Sign up to request clarification or add additional context in comments.

1 Comment

sorry because I write not clear. I will edit my question
0

The answer is pretty simple, for each user you have to loop through the columns to display.

<% @user.each do |user| %>
  <% @user_form_column_list.each do |column| %>
    <%= user[column.db_column_name] # assuming the db_column_name holds the user attribute %>
  <% end %>
<% end %>

I left out any HTML to simplify the answer.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.