Hi, I have a question that Is it possible to add record into the database table without adding the model for that? E.g. I have a table customers. And I haven''t created a model for that. Can I add a record into that table bu doing "cust=Custome.new cust.save" Any help appreciated. Thanks, Tushar -- Posted via http://www.ruby-forum.com/.
2009/9/29 Tushar Gandhi <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>:> > Hi, > I have a question that Is it possible to add record into the database > table without adding the model for that? > > E.g. I have a table customers. And I haven''t created a model for that. > Can I add a record into that table bu doing "cust=Custome.new cust.save" >You can''t do Customer.new unless the Customer class is defined. Otherwise how would ruby know what to do? All you need is models/customer.rb containing class Customer < ActiveRecord::Base end Provided the customer table meets the normal Rails conventions (primary key id and so on). Colin
If you don''t want to create a model you can use straight SQL with ActiveRecord::Base.connection.execute. I would create the model, though. It would be the hell of a lot simpler and cleaner. On Sep 29, 5:37 am, Tushar Gandhi <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Hi, > I have a question that Is it possible to add record into the database > table without adding the model for that? > > E.g. I have a table customers. And I haven''t created a model for that. > Can I add a record into that table bu doing "cust=Custome.new cust.save" > > Any help appreciated. > Thanks, > Tushar > -- > Posted viahttp://www.ruby-forum.com/.
The model was used for controller connected database.Otherwise, you can use straight SQL with ActiveRecord::Base.connection.execute.I would like to use model On Tue, Sep 29, 2009 at 5:37 PM, Tushar Gandhi < rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Hi, > I have a question that Is it possible to add record into the database > table without adding the model for that? > > E.g. I have a table customers. And I haven''t created a model for that. > Can I add a record into that table bu doing "cust=Custome.new cust.save" > > Any help appreciated. > Thanks, > Tushar > -- > Posted via http://www.ruby-forum.com/. > > > >-- Sons of Gondor, of Rohan, my brothers! I see in your eyes the same fear that would take the heart of me. A day may come when the courage of men fails when we forsake our friends and break all bonds of fellowship. But this is not this day. And hour of wolves and shattered shields when the age of Men comes crashing down. But this is not this day! This day we fight! By all that you hold dear on this good earth, I bid you stand! Men of the West! --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---