rubyonrailsin

A Ruby and Rails talk

Tuesday, March 16, 2010


[Rails] SQL result to String conversion

by rubyonrailsin 0 comments

Tag


Share this post:
Design Float
StumbleUpon
Reddit

Hello All,

I am very new to Ruby on Rails and I have a quick question for you all,
which is as follows:

I have this following line of code in an partial that renders itself on
the posts/index view:
Created By (User): <%= User.find(:all, :select => 'name', :conditions =>
["id = ?", 1]) %>
(I am hard-coding that '1' there)

Now, when I run the server; the above line of code displays just the '#'
symbol.. nothing else (no name is displayed :-( ):
Created By (User): #

I have the following tables: User, Post & Comment. For your reference, I
am also pasting here the contents of my 'User' table that I got from my
console:

>> User.find(:all)
=> [#<User id: 1, name: "Ron", created_at: "2010-03-15 02:45:28",
updated_at: "2010-03-15 02:45:28">, #<User id: 2, name: "David",
created_at: "2010-03-15 21:13:22", updated_at: "2010-03-15 21:13:22">,
#<User id: 3, name: "Tom", created_at: "2010-03-15 21:38:31",
updated_at: "2010-03-15 21:38:31">, #<User id: 4, name: "John",
created_at: "2010-03-15 21:38:43", updated_at: "2010-03-15 21:38:43">,
#<User id: 5, name: "Harry", created_at: "2010-03-15 21:38:50",
updated_at: "2010-03-15 21:38:50">, #<User id: 6, name: "Martin",
created_at: "2010-03-15 21:38:57", updated_at: "2010-03-15 21:38:57">]


Can you please let me me know if I am missing something here or if I am
doing anything wrong?
--
Posted via http://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

No comments:

Post a Comment

Subscribe feeds via e-mail

Blog Archive