Datamapper into String

大兔子大兔子 提交于 2020-01-06 01:30:14

问题


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  

result in terminal;

#< Twitchtvst:0x007fb48b4d5a98 > 

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


Opppppsss!

Here is the real code sample. Sorry!

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

If I add .to_s at users_stream it does not work


回答1:


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



回答2:


You're getting a Collection of Twitchtvst objects, so you need to convert each to a String:

puts Twitchtvst.all.map(&:to_s).join


来源:https://stackoverflow.com/questions/22117856/datamapper-into-string

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!