2

I created a view and was able to successfully access it through rails by creating the view through a migration with execute sql.

The problem with this is that the view is not entered into the schema. So when I need to create my test database to run my tests against the view is not created. I then need to create it by running the sql statement. Is there a way to implement SQL views elegantly in ruby on rails?

My environment: Ruby on Rails 3.0.3 PostgreSQL 8.3

2 Answers 2

1

The rails_sql_views gem is intended to solve this problem. It adds support to the schema dumper to include views, which means you can use them in your test database. I'm not sure how well it works in Rails 3, but the github issues list has a pull request that appears to add Rails 3 support.

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

2 Comments

This did solve my problem although there were a few pauses for concern. I had to edit the code for it to work with Postgres.
Nicolo77> Could you share what code change you made to make the gem work with postgres?
0

Possibly. using config.active_record.schema_format = :sql may help.

Comments

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.