Inject SQL Statement in Rails

J

Jojo Mojo

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!
 
Y

yudi

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.
 
J

Jojo Mojo

yudi said:
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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,274
Messages
2,571,365
Members
48,049
Latest member
robinsonkoff

Latest Threads

Top