[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Inject SQL Statement in Rails

Jojo Mojo

12/12/2007 3:23:00 AM

Hi,

I have a simple SQL statement which I would like to inject in my web
application. The SQL statement is:

Select course_id
from degrees
where programme_id = 1

I need to know the step by step on how to make this work. What changes
should be made to the model, view or controller? Urgent. Please reply
asap.
Thank you very much!
--
Posted via http://www.ruby-....

4 Answers

yudi

12/12/2007 3:34:00 AM

0

Note: parts of this message were removed by the gateway to make it a legal Usenet post.

You can use find_by_sql to use MySQL directly:

@object.find_by_sql("SELECT course_id
FROM degrees
WHERE programme_id = 1
")

@object will be referenced with an array of entries from database.

On Dec 11, 2007 9:22 PM, Jojo Mojo <lonexenophobia@hotmail.com> wrote:

> Hi,
>
> I have a simple SQL statement which I would like to inject in my web
> application. The SQL statement is:
>
> Select course_id
> from degrees
> where programme_id = 1
>
> I need to know the step by step on how to make this work. What changes
> should be made to the model, view or controller? Urgent. Please reply
> asap.
> Thank you very much!
> --
> Posted via http://www.ruby-....
>
>


--
Do not be afraid of Change.

Jojo Mojo

12/13/2007 12:30:00 AM

0

yudi wrote:
> You can use find_by_sql to use MySQL directly:
>
> @object.find_by_sql("SELECT course_id
> FROM degrees
> WHERE programme_id = 1
> ")
>
> @object will be referenced with an array of entries from database.

okay so i put this statement in the model right?

just curious, how does the view/controller know where to find this?
--
Posted via http://www.ruby-....

yudi

12/13/2007 1:21:00 AM

0

[Note: parts of this message were removed to make it a legal post.]

Check RailsEnvy for an ActiveRecord tutorial. You'll find everything you
need over therehttp://www.railsenvy.com/2007/8/8/activerecor...



On Dec 12, 2007 6:30 PM, Jojo Mojo <lonexenophobia@hotmail.com> wrote:

> yudi wrote:
> > You can use find_by_sql to use MySQL directly:
> >
> > @object.find_by_sql("SELECT course_id
> > FROM degrees
> > WHERE programme_id = 1
> > ")
> >
> > @object will be referenced with an array of entries from database.
>
> okay so i put this statement in the model right?
>
> just curious, how does the view/controller know where to find this?
> --
> Posted via http://www.ruby-....
>
>


--
Do not be afraid of Change.

Jojo Mojo

12/13/2007 1:33:00 AM

0

thanks everyone for all the help!
--
Posted via http://www.ruby-....