In PHP from form we get values in POST OR GET than I use mysql_query(insert_value) what is its equal in ROR -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Jun 23, 2010, at 10:13 AM, Ali Imran wrote:> In PHP from form > > we get values in POST OR GET > > > than I use mysql_query(insert_value) > > what is its equal in ROR >http://guides.rails.info/getting_started.html http://guides.rails.info/active_record_querying.html -philip> -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Philip has given good links. Basically all the database related stuffs are handled by the Active Record class which is one of the components of MVC(Model View Controller) architecture. Rails handles the create record stuff the same way traditional programming languages such as C++ via new constructor. If you want to add a new employee detail record the statement would be emp1 = emp.new(:name=>"amala", :website=>"http://www.tamil.net", :email=>" a@b.com") emp1.save or emp.new(:name=>"amala", :website=>"http://www.tamil.net", :email=>"a@b.com ").save The fantastic feature of ROR is, mostly you dont need to know SQL query language, or you dont need to apply another Query language syntax. The code becomes fantastically simple and readable from the functional point of view. On 23 June 2010 18:22, Philip Hallstrom <philip-LSG90OXdqQE@public.gmane.org> wrote:> > On Jun 23, 2010, at 10:13 AM, Ali Imran wrote: > > > In PHP from form > > > > we get values in POST OR GET > > > > > > than I use mysql_query(insert_value) > > > > what is its equal in ROR > > > > http://guides.rails.info/getting_started.html > http://guides.rails.info/active_record_querying.html > > -philip > > > > -- > > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > > > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- -- Nandri(Thanks in Tamil), Amala Singh -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Thanks... I try this and its work ... <% @obj= params[:category] @catid=@obj["catid"] @newrec= Category.new(:catid=>@catid) @newrec.save %> but when i try to do this like this.. its not working ... reason it is different because ... I have only controller for "Category" and i have model for "contact" but not controller .. willl it work with one single controller or not <% @obj= params[:contact] @name=@obj["name"] @newrec= Contact.new(:name=>@name) @newrec.save %> On Jun 23, 11:29 am, Amala Singh <amalasi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Philip has given good links. > > Basically all the database related stuffs are handled by the Active Record > class which is one > of the components of MVC(Model View Controller) architecture. > > Rails handles the create record stuff the same way traditional programming > languages such > as C++ via new constructor. > > If you want to add a new employee detail record the statement would be > > emp1 = emp.new(:name=>"amala", :website=>"http://www.tamil.net", :email=>" > a...@b.com") > emp1.save > > or > > emp.new(:name=>"amala", :website=>"http://www.tamil.net", :email=>"a...@b.com > ").save > > The fantastic feature of ROR is, mostly you dont need to know SQL query > language, or > you dont need to apply another Query language syntax. > > The code becomes fantastically simple and readable from the functional point > of view. > > On 23 June 2010 18:22, Philip Hallstrom <phi...-LSG90OXdqQE@public.gmane.org> wrote: > > > > > > > On Jun 23, 2010, at 10:13 AM, Ali Imran wrote: > > > > In PHP from form > > > > we get values in POST OR GET > > > > than I use mysql_query(insert_value) > > > > what is its equal in ROR > > >http://guides.rails.info/getting_started.html > >http://guides.rails.info/active_record_querying.html > > > -philip > > > > -- > > > 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-/JYPxA39Uh4Ykp1iOSErHA@public.gmane.orgm. > > > To unsubscribe from this group, send email to > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > > . > > > For more options, visit this group at > >http://groups.google.com/group/rubyonrails-talk?hl=en. > > > -- > > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > > . > > For more options, visit this group at > >http://groups.google.com/group/rubyonrails-talk?hl=en. > > -- > -- > Nandri(Thanks in Tamil), > Amala Singh-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hm, why are you using <% %>? Is this code in your viewer? Do you have a column "catid" for your model Category? Could you please describe better what your models look like and what kind of relationship do they have between them? Thanks, Fernando Brito -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
There is no relationship between models. but i only have one controller and trying to control two models with it it is possible.. On Jun 23, 11:56 am, Fernando Brito <em...-7WGqr3rU1tXSv/CSzVJHWQC/G2K4zDHf@public.gmane.org> wrote:> Hm, why are you using <% %>? Is this code in your viewer? > Do you have a column "catid" for your model Category? > > Could you please describe better what your models look like and what kind of > relationship do they have between them? > > Thanks, > Fernando Brito-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Ali, Before you are trying out in the view, use the console and try out that what you want to with the models. using ruby script/console in the project directory. Then go step by step with the views. Go through the tutorials first. We can not teach you basics here. On 23 June 2010 18:59, Ali Imran <ali.imran.rana-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> There is no relationship between models. but i only have one > controller and trying to control two models with it > > it is possible.. > > > On Jun 23, 11:56 am, Fernando Brito <em...-7WGqr3rU1tXSv/CSzVJHWQC/G2K4zDHf@public.gmane.org> wrote: > > Hm, why are you using <% %>? Is this code in your viewer? > > Do you have a column "catid" for your model Category? > > > > Could you please describe better what your models look like and what kind > of > > relationship do they have between them? > > > > Thanks, > > Fernando Brito > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- -- Nandri(Thanks in Tamil), Amala Singh -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Thanks buddy. On Jun 23, 12:16 pm, Amala Singh <amalasi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Ali, > > Before you are trying out in the view, use the console and try out that > what you want to with the models. > using > ruby script/console in the project directory. > > Then go step by step with the views. > > Go through the tutorials first. > > We can not teach you basics here. > > On 23 June 2010 18:59, Ali Imran <ali.imran.r...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > There is no relationship between models. but i only have one > > controller and trying to control two models with it > > > it is possible.. > > > On Jun 23, 11:56 am, Fernando Brito <em...-7WGqr3rU1tXSv/CSzVJHWQC/G2K4zDHf@public.gmane.org> wrote: > > > Hm, why are you using <% %>? Is this code in your viewer? > > > Do you have a column "catid" for your model Category? > > > > Could you please describe better what your models look like and what kind > > of > > > relationship do they have between them? > > > > Thanks, > > > Fernando Brito > > > -- > > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > > . > > For more options, visit this group at > >http://groups.google.com/group/rubyonrails-talk?hl=en. > > -- > -- > Nandri(Thanks in Tamil), > Amala Singh-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Ali Imran wrote:> <% > > @obj= params[:category] > > @catid=@obj["catid"] > > @newrec= Category.new(:catid=>@catid) > @newrec.save > > %>As far a I see it there are two primary patterns that you may not be accustomed to coming from the PHP world. Plus one principal you may be struggling against. Patterns: 1. Model-View-Controller (MVC) 2. Object Relational Mapping (ORM). 1. Rails conforms, rather strictly, to the Model-View-Controller (MVC) design pattern. There are many articles available on MVC. Learn it, live it, & love it. Otherwise, you''ll continue to struggle with Rails, and it will seem to fight against you. 2. ActiveRecord implements the Object Relational Mapping (ORM) design pattern. ORM is designed to abstract away SQL generation from higher level business logic. There are a few distinct advantages to this abstraction: a) Business and application logic are written a single language syntax, Ruby. b) SQL generation is handled by database adaptors, which hide (abstract) business logic from database implementation details. The underlying database can be easily replaced with an entirely different database engine without having to rewrite application and/or business logic. Principals: 1. Convention Over Configuration Convention Over Configuration was one of the primary principals that drew my interest to Ruby on Rails. For example, I notice that you mentioned a column named "catid." It appears that this column may be serving as the primary key of the "categories" table, which would be represented by the "Category" class. The Rails convention would suggest that the primary key of this, and any other, table should be named "id." The idea put forth by Convention Over Configuration is to make certain "default" assumptions as follows: A model named "Category" would expect a database table named "categories" containing a primary key named "id." In nearly all cases these "defaults" can be overridden, but learning and following the convention can greatly ease the burden of development and provide consistency both within a project and across projects. The sheer lack of convention, and the hundreds of configuration files that weigh down the development process of most Java based web frameworks led me to investigate alternative languages and frameworks for building web applications. My discovery of Ruby on Rails was a delightful surprise. It is a framework that "thinks" the way I think. I was hooked from the start. Programming in Ruby reminded me of why I got into computer programming in the first place. I''ve had more fun learning Ruby on Rails, and developing applications with the framework than in the entirety of my relatively long Java career. I''m still mostly stuck in the Java world for my day job, but at least I can enjoy the joys of RoR for my personal projects. I say all this for one primary reason, which is to say, "Approach learning Ruby on Rails on its terms, not on your own. Don''t fight against its patterns simply because you did things a different way in other languages or frameworks." I hope you are soon able to embrace of beauty, consistency, and solid foundation that Ruby on Rails provides. Good luck and have fun. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Thanks buddy, This is great help for just starter. I spend a lot of time on just to understand this MVC. You are right this is a big difference between PHP and ROR. On Jun 24, 8:01 am, Robert Walker <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Ali Imran wrote: > > <% > > > @obj= params[:category] > > > @catid=@obj["catid"] > > > @newrec= Category.new(:catid=>@catid) > > @newrec.save > > > %> > > As far a I see it there are two primary patterns that you may not be > accustomed to coming from the PHP world. Plus one principal you may be > struggling against. > > Patterns: > 1. Model-View-Controller (MVC) > 2. Object Relational Mapping (ORM). > > 1. Rails conforms, rather strictly, to the Model-View-Controller (MVC) > design pattern. There are many articles available on MVC. Learn it, live > it, & love it. Otherwise, you''ll continue to struggle with Rails, and it > will seem to fight against you. > > 2. ActiveRecord implements the Object Relational Mapping (ORM) design > pattern. ORM is designed to abstract away SQL generation from higher > level business logic. There are a few distinct advantages to this > abstraction: a) Business and application logic are written a single > language syntax, Ruby. b) SQL generation is handled by database > adaptors, which hide (abstract) business logic from database > implementation details. The underlying database can be easily replaced > with an entirely different database engine without having to rewrite > application and/or business logic. > > Principals: > 1. Convention Over Configuration > > Convention Over Configuration was one of the primary principals that > drew my interest to Ruby on Rails. For example, I notice that you > mentioned a column named "catid." It appears that this column may be > serving as the primary key of the "categories" table, which would be > represented by the "Category" class. > > The Rails convention would suggest that the primary key of this, and any > other, table should be named "id." The idea put forth by Convention Over > Configuration is to make certain "default" assumptions as follows: A > model named "Category" would expect a database table named "categories" > containing a primary key named "id." In nearly all cases these > "defaults" can be overridden, but learning and following the convention > can greatly ease the burden of development and provide consistency both > within a project and across projects. > > The sheer lack of convention, and the hundreds of configuration files > that weigh down the development process of most Java based web > frameworks led me to investigate alternative languages and frameworks > for building web applications. > > My discovery of Ruby on Rails was a delightful surprise. It is a > framework that "thinks" the way I think. I was hooked from the start. > Programming in Ruby reminded me of why I got into computer programming > in the first place. I''ve had more fun learning Ruby on Rails, and > developing applications with the framework than in the entirety of my > relatively long Java career. I''m still mostly stuck in the Java world > for my day job, but at least I can enjoy the joys of RoR for my personal > projects. > > I say all this for one primary reason, which is to say, "Approach > learning Ruby on Rails on its terms, not on your own. Don''t fight > against its patterns simply because you did things a different way in > other languages or frameworks." I hope you are soon able to embrace of > beauty, consistency, and solid foundation that Ruby on Rails provides. > > Good luck and have fun. > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 24 Jun 2010, at 16:39, Ali Imran wrote:> Thanks buddy, This is great help for just starter. > > I spend a lot of time on just to understand this MVC. You are right > this is a big difference between PHP and ROR.Depends on whether you have used a FRAMEWORK in PHP before. PHP frameworks such as CakePHP, Symphony, etc. work very similarly to Rails. Ruby and PHP are both languages and they use the same concepts, with a different syntax, that''s all. But yes, if you''re used to just injecting SQL code into HTML pages and then rendering that out, the whole MVC thing will seem quite daunting, but it''s for the better. Best regards Peter De Berdt -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.