问题
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