# Querying using Ruby on Rails

**URL:** <https://www.ruby-forum.com/t/querying-using-ruby-on-rails/103884>\
**Category:** Rails\
**Created:** [May 11, 2007, 9:21am UTC](https://www.ruby-forum.com/t/querying-using-ruby-on-rails/103884 "2007-05-11T09:21:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![venugopal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/ee7513/32.png) [@venugopal](https://www.ruby-forum.com/u/venugopal)\
**Post date:** [May 11, 2007, 9:21am UTC](https://www.ruby-forum.com/t/querying-using-ruby-on-rails/103884/1 "2007-05-11T09:21:05Z")

</div>

Hi Everyone…

I’need to query using Ruby on rails…dynamically rather than hard  
coding the  
statement like:  
select\* from authors where name=“Hello”;

i need to get the value of the name from a text box in the earlier page  
and transfer the value to the next page and have a statement like

select \* from author where name=" #{@username}"

similar to this so tat my search could be dynamic …

i’ve tried with find\_by\_sql… but don’t know which file i need to add  
the code…

Thanks & Regards

Venugopal

---

<div class="post-metadata">

**Author:** ![venugopal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/ee7513/32.png) [@venugopal](https://www.ruby-forum.com/u/venugopal)\
**Post date:** [May 11, 2007, 9:56am UTC](https://www.ruby-forum.com/t/querying-using-ruby-on-rails/103884/2 "2007-05-11T09:56:35Z")

</div>

Hey,

In Rails you rarely need to use find\_by\_sql.

You can easily do things like this with  
Author.find\_by\_name(username)

Why don’t read a bit more about ActiveRecord and Rails in general?

Cheers,  
Yuri

On 5/11/07, Venugopal [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Venugopal
> 
> –  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> >

–  
Best regards,  
Yuri L.

---

<div class="post-metadata">

**Author:** ![venugopal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/ee7513/32.png) [@venugopal](https://www.ruby-forum.com/u/venugopal)\
**Post date:** [May 11, 2007, 10:24am UTC](https://www.ruby-forum.com/t/querying-using-ruby-on-rails/103884/3 "2007-05-11T10:24:39Z")

</div>

Or…

Author.find(:all, :conditions =\> {:username =\> @username })  
replace :all, for :first if needed.

Zach I.  
â†’ Blog â€” [http://www.zachinglis.com](http://www.zachinglis.com)  
â†’ Company â€” [http://www.lt3media.com](http://www.lt3media.com)  
â†’ Portfolio â€” [http://portfolio.zachinglis.com](http://portfolio.zachinglis.com)
