[LRUG] Rails and DB Views

Olly Legg ollylegg at gmail.com
Fri Jan 17 03:32:29 PST 2014


I haven't used database views before, but I *think* you should switch to using a SQL schema, using `config.active_record.schema_format` (http://guides.rubyonrails.org/configuring.html#configuring-active-record) and you can then use ActiveRecord::Connection#execute to create & manage your views (http://guides.rubyonrails.org/migrations.html#when-helpers-aren-t-enough).

It should Just Work™.

On 17 Jan 2014, at 11:20, Ed James (Alt) <ed.james.spam at gmail.com> wrote:

> Hi all
> 
> Is anyone using db views in a Rails app? If so, maybe you can help. 
> 
> My issue lies more around the management of the views, rather than using them in the app. I’ve done this before in a previous project but I don’t have access to that codebase anymore and I can’t remember what the hell I did.
> How do you make ActiveRecord recognise the view and exclude it from the schema.rb file?
> I seem to remember keeping the views as .sql files which were executed after a migration (by enhancing the db:migrate task). Any variations on this?
> The only gem I’ve managed to find is this one: https://github.com/railsware/db_structure_ext/tree/master/lib/db_structure_ext
> Seems very old though and this seems like something which doesn’t need a gem. I know we didn’t use one previously.
> 
> Unfortunately using the word “view” in search criteria is not very useful ;)
> 
> Thanks,
> Ed.
> _______________________________________________
> Chat mailing list
> Chat at lists.lrug.org
> http://lists.lrug.org/listinfo.cgi/chat-lrug.org

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lrug.org/pipermail/chat-lrug.org/attachments/20140117/4049e3c4/attachment-0003.html>


More information about the Chat mailing list