mysql - 如何在 ruby​​ on rails 中获取 Object 的值

标签 mysql ruby-on-rails ruby ruby-on-rails-3

我想从对象结果中打印特定值。这是我正在执行 SQL 查询并从 View 表中获取所有数据,所有数据都来自“Employee_Information” View (表)。 hr_controller.rb

class HrController < ApplicationController

  def internal_employee_page        
    @employees = MysqlConnection.connection.select_all("SELECT * FROM Employee_Information")
  end 
end

internal_employee_page.html.erb这是我的第一个 View

<div id="job_details">
    <% @employees.each do |emp| %>
        <%= render partial: "hr/employee_details", locals: {emp: emp} %>
    <% end %>               
</div>

_employee_details.html.erb这是我的第二个观点

<h3> User Name : <%= emp%> </h3>

像这样我试图打印所有值 然后我得到了以下结果 enter image description here 我想打印每个值 我在第二个 View 中也尝试过

<h3> User Name : <%= emp.full_name%> </h3>

但是我得到了错误: enter image description here 请帮助我,我根据我的知识尝试了每件事,我哪里错了,有什么问题

最佳答案

试试这个:

<h3> User Name : <%= emp["full_name"] %> </h3>

关于mysql - 如何在 ruby​​ on rails 中获取 Object 的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39792366/

相关文章:

css - 为什么在 rails 中链接 css 中的图像时使用 ASSET_PATH 而不是 Image-url

mysql - SQL查询以计算按ID分组的行,但限制每个组的计数

mysql - 连接两个 select 语句的结果

ruby-on-rails - rails : Form Submit Perform Two Actions

ruby-on-rails - Rails heroku 部署错误

ruby-on-rails - AWS S3 : The bucket you are attempting to access must be addressed using the specified endpoint

ruby - 如何使用 Ruby + Regex 编写内部自然语言 DSL?

mysql - 无法在 jenkins 上创建 PoolableConnectionFactory

mysql - 使用嵌套的选择查询插入到另一个表中

sql - 榜样 Gem : How to get all Users with role: [:admin, :mentor]