Hi, I''m a complete newbie to this, I''m afraid. Apologies if this has been answered elsewhere, but I''ve had a look, and can''t find the answers I''m looking for, especially for using Rails 2.0. We have an existing database which we would need to connect Rails to, and the database structure is not what Rails would seem to expect. Firstly, tables are not always pluralised. Secondly, some primary keys are not integers. Thirdly, some primary keys are composite. Now if I''m correct, I would need to do the following, eg. for an "ENTITY" table: script/generate scaffold entity {field definitions here} --skip- migration Is there any way to avoid having to type in all of the field definitions manually? Then I would need to edit models/entity.rb and specify the following: class Entity < ActiveRecord::Base set_table_name "entity" set_primary_key "en_key" end That should, I believe, take care of the table names not conforming to the Rails convention. What about the primary keys? Is there anything else I''m missing? Sorry to trouble you guys with all of this, but in all honesty, the documentation seems non-existent for this area - and I''m sure many people that look to use Rails have existing databases that do not conform to the conventions. Just in case it makes any difference, the database I''m looking to use is a Firebird db. Thanks in advance for any help you can give me. Cheers Ashley --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Ashley wrote:> Firstly, tables are not always pluralised.You can define the table name the model should look for within the model itself with set_table_name.> Secondly, some primary keys are not integers.You poor soul. Are they numbers (even if held as strings)? If so you can access the value before it gets type casted, or cast it yourself when you need it. Rails RDoc for that: http://api.rubyonrails.com/classes/ActiveRecord/Base.html#M001449> Thirdly, some primary keys are composite.There is at least one plugin that handles composite keys. Google should find it for you. Finally, here are a couple guides for working with legacy databases. http://sl33p3r.free.fr/tutorials/rails/legacy/legacy_databases.html http://wiki.rubyonrails.org/rails/pages/howtouselegacyschemas Good luck. You''re going to need it. ;) -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks very much for your reply Daniel. Can I assume that there isn''t any way to get Rails to read the table fields, that the fields have to be defined manually when calling scaffold? Also, and seemingly more importantly, am I to assume that perhaps Rails isn''t the way to go if our primary keys aren''t always integers? They are often strings, and not just numbers stored as strings, eg ''AL''. Once again, thanks for your help and for the links you''ve provided, they are very much appreciated. Cheers Ashley On Apr 9, 6:21 pm, Daniel Waite <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Ashley wrote: > > Firstly, tables are not always pluralised. > > You can define the table name the model should look for within the model > itself with set_table_name. > > > Secondly, some primary keys are not integers. > > You poor soul. Are they numbers (even if held as strings)? If so you can > access the value before it gets type casted, or cast it yourself when > you need it. > > Rails RDoc for that:http://api.rubyonrails.com/classes/ActiveRecord/Base.html#M001449 > > > Thirdly, some primary keys are composite. > > There is at least one plugin that handles composite keys. Google should > find it for you. > > Finally, here are a couple guides for working with legacy databases. > > http://sl33p3r.free.fr/tutorials/rails/legacy/legacy_databases.htmlhttp://wiki.rubyonrails.org/rails/pages/howtouselegacyschemas > > Good luck. You''re going to need it. ;) > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Can anyone give advice on the two questions I''ve asked? Thanks again to anyone that can help. On Apr 10, 2:29 pm, Ashley <ash.ll...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> Thanks very much for your reply Daniel. > > Can I assume that there isn''t any way to get Rails to read the table > fields, that the fields have to be defined manually when calling > scaffold? > > Also, and seemingly more importantly, am I to assume that perhaps > Rails isn''t the way to go if our primary keys aren''t always integers? > They are often strings, and not just numbers stored as strings, eg > ''AL''. > > Once again, thanks for your help and for the links you''ve provided, > they are very much appreciated. > > Cheers > > Ashley > > On Apr 9, 6:21 pm, Daniel Waite <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > wrote: > > > Ashley wrote: > > > Firstly, tables are not always pluralised. > > > You can define the table name the model should look for within the model > > itself with set_table_name. > > > > Secondly, some primary keys are not integers. > > > You poor soul. Are they numbers (even if held as strings)? If so you can > > access the value before it gets type casted, or cast it yourself when > > you need it. > > > Rails RDoc for that:http://api.rubyonrails.com/classes/ActiveRecord/Base.html#M001449 > > > > Thirdly, some primary keys are composite. > > > There is at least one plugin that handles composite keys. Google should > > find it for you. > > > Finally, here are a couple guides for working with legacy databases. > > >http://sl33p3r.free.fr/tutorials/rails/legacy/legacy_databases.htmlht... > > > Good luck. You''re going to need it. ;) > > -- > > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Apr 14, 4:16 pm, Ashley <ash.ll...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> Can anyone give advice on the two questions I''ve asked? Thanks again > to anyone that can help. > > On Apr 10, 2:29 pm, Ashley <ash.ll...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > > > Thanks very much for your reply Daniel. > > > Can I assume that there isn''t any way to get Rails to read the table > > fields, that the fields have to be defined manually when calling > > scaffold?I don''t think there is, but maybe a bit of perl or ruby working off the outputs of a SQL ''describe table'' command might do the trick. May be Dr Nic''s Magic Models (Google for it) can tell you how Rails is interpreting your db without too much effort on your part.> > > Also, and seemingly more importantly, am I to assume that perhaps > > Rails isn''t the way to go if our primary keys aren''t always integers? > > They are often strings, and not just numbers stored as strings, eg > > ''AL''.I''m not sure if Rails really cares too much about this, but I am speaking from a position of ignorance. Give it a go and see what happens. Allan --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Maybe this is of interest: http://www.elctech.com/blog/refreshing-rails-generated-views Allan --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Just to end the thread, Allan''s top on Dr Nic''s Magic Models proved very useful. As I said before, thanks a lot Allan, and to Daniel Waite initially. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---