数据映射器转换为字符串 [英] Datamapper into String

查看:79
本文介绍了数据映射器转换为字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够看到类似数据库中的TwitchTV名称的字符串。这是我当前的代码

I want to be able to see the string like the TwitchTV name I have in my database. Here is my current code

get '/watch/:id' do |id|
  erb :mystream
  @result = Twitchtvst.all( :fields => [:Twitchtv ], 
               :conditions => { :user_id => "#{id}" }           
             )  
  puts @result              
end  

终端产生的结果;

#< Twitchtvst:0x007fb48b4d5a98 > 

如何将其放入字符串中(数据库中的TwitchTV答案)

How do I get that into a string (TwitchTV answer in database)

Opppppsss!

Opppppsss!

这是真实的代码示例。抱歉!

Here is the real code sample. Sorry!

  get '/livestream' do
    erb :livestream
    @users_streams = Twitchtvst.all   
    puts @users_streams
  end

如果我在users_stream上添加.to_s,则不会工作

If I add .to_s at users_stream it does not work

推荐答案

通过添加 .to_csv ,不完全是一个字符串,但是它应该显示内容:

By adding .to_csv, not exactly a string, but it should show the content:

get '/livestream' do
    erb :livestream
    @users_streams = Twitchtvst.all   
    @users_streams.each do |us|
        p us.to_csv
    end
  end

这篇关于数据映射器转换为字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆