2

How can i solve this problems if i dont't use injection sql command in controller?

More detailsenter image description here

2 Answers 2

1

See this question:

http://www.stackoverflow.com/questions/4727470/how-to-make-rails-external-database-calls

Basically, the point is that you can define the connection to the other database in database.yml. ActiveRecord::Base will inherit from one by default, but you can use the establish_connection method to connect to the other database that you've configured for a given model.

Then you can use the ActiveRecord API (e.g. find_by_sql) to query the other database.

Sign up to request clarification or add additional context in comments.

1 Comment

I thought 'establish_connection' is a good idea to solved. Thanks,
1

I think you won't (or at least shouldn't) get around using at least ActiveRecord models and querying them using find_by_sql.

Refer to: http://api.rubyonrails.org/classes/ActiveRecord/Querying.html#method-i-find_by_sql

2 Comments

um mayby 'Rails's creator' get read this and solved this problem soon hahaha , Thank for your answer but i still to solve it except sql command.
find_by_sql is one of solution you can do then you want to queries other tables that still in rails project (the same database) and will not work within queries to another database.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.