Hello there, I am new to the rails framework. I have seen that rails uses the "Convention over configuration" philosophy. Then when I create a controller "post_controller" I have to actually configure it in the routes.rb file to get it working. Is this the other way around, configuration over convention? I would expect that if the controller exist all his actions are available to be executed, and more to go actions for crud would accept the "conventional" method and have names like create, delete etc... What do you think? Correct me if I am wrong in something. Friendly and geeky, Tydeas -- 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 Wed, Mar 14, 2012 at 10:28 AM, tydeas <tydeas.dr-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hello there, > I am new to the rails framework. I have seen that rails uses the > "Convention over configuration" philosophy. > Then when I create a controller "post_controller" I have to actually > configure it in the routes.rb file to get it working. Is this the > other way around, configuration over convention? > I would expect that if the controller exist all his actions are > available to be executed, and more to go actions for crud would accept > the "conventional" method and have names like create, delete etc... > What do you think? Correct me if I am wrong in something.Try this peterv@e6500:~/b/projects/my_contacts$ rails generate resource foo invoke active_record create db/migrate/20120314225352_create_foos.rb create app/models/foo.rb invoke rspec create spec/models/foo_spec.rb invoke factory_girl create spec/factories/foos.rb invoke controller create app/controllers/foos_controller.rb invoke erb create app/views/foos invoke rspec create spec/controllers/foos_controller_spec.rb invoke assets invoke coffee create app/assets/javascripts/foos.js.coffee invoke scss create app/assets/stylesheets/foos.css.scss route resources :foos peterv@e6500:~/b/projects/my_contacts$ rails destroy resource foo invoke active_record remove db/migrate/20120314225352_create_foos.rb remove app/models/foo.rb invoke rspec remove spec/models/foo_spec.rb invoke factory_girl remove spec/factories/foos.rb invoke controller remove app/controllers/foos_controller.rb invoke erb remove app/views/foos invoke rspec remove spec/controllers/foos_controller_spec.rb invoke assets invoke coffee remove app/assets/javascripts/foos.js.coffee invoke scss remove app/assets/stylesheets/foos.css.scss route resources :foos This will also auto generate the correct routing line. Note that you can use ''destroy'' to remove all auto-created files. You might look into other rails generators with $ rails generate HTH, Peter -- 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.
The 14/03/12, tydeas wrote:> Hello there, > I am new to the rails framework. I have seen that rails uses the > "Convention over configuration" philosophy. > Then when I create a controller "post_controller" I have to actually > configure it in the routes.rb file to get it working. Is this the > other way around, configuration over convention? > I would expect that if the controller exist all his actions are > available to be executed, and more to go actions for crud would accept > the "conventional" method and have names like create, delete etc... > What do you think? Correct me if I am wrong in something.Convention is done the reverse way. Requesting for users/new will execute method new of class UsersController in controllers/user_controller.rb. All this naming is conventionnal. BTW, I wouldn''t expect to have routes automagically relying on controllers because controllers often doesn''t have routes attached. -- Nicolas Sebrecht -- 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.
That''s what exactly I am trying to explain and think the issue is. You have convention on how to configure something where you should had convention to avoid configuration (at least when still in the beginning of your development process). So let me describe what imho is proper convention over configuration in this case. If I have a rb file in my controllers folder with is named *_controller, for example foo_controller, then every method prefixed with action_* like action_bar is accessible through foo/bar. This way I have a convention to avoid configuration in the first steps of my development. Then I can use routes.rb to change and configure. On Thursday, March 15, 2012 3:12:53 PM UTC+2, Nicolas Sebrecht wrote:> > The 14/03/12, tydeas wrote: > > Hello there, > > I am new to the rails framework. I have seen that rails uses the > > "Convention over configuration" philosophy. > > Then when I create a controller "post_controller" I have to actually > > configure it in the routes.rb file to get it working. Is this the > > other way around, configuration over convention? > > I would expect that if the controller exist all his actions are > > available to be executed, and more to go actions for crud would accept > > the "conventional" method and have names like create, delete etc... > > What do you think? Correct me if I am wrong in something. > > Convention is done the reverse way. Requesting for users/new will > execute method new of class UsersController in > controllers/user_controller.rb. All this naming is conventionnal. > > BTW, I wouldn''t expect to have routes automagically relying on > controllers because controllers often doesn''t have routes attached. > > -- > Nicolas Sebrecht > >On Thursday, March 15, 2012 3:12:53 PM UTC+2, Nicolas Sebrecht wrote:> > The 14/03/12, tydeas wrote: > > Hello there, > > I am new to the rails framework. I have seen that rails uses the > > "Convention over configuration" philosophy. > > Then when I create a controller "post_controller" I have to actually > > configure it in the routes.rb file to get it working. Is this the > > other way around, configuration over convention? > > I would expect that if the controller exist all his actions are > > available to be executed, and more to go actions for crud would accept > > the "conventional" method and have names like create, delete etc... > > What do you think? Correct me if I am wrong in something. > > Convention is done the reverse way. Requesting for users/new will > execute method new of class UsersController in > controllers/user_controller.rb. All this naming is conventionnal. > > BTW, I wouldn''t expect to have routes automagically relying on > controllers because controllers often doesn''t have routes attached. > > -- > Nicolas Sebrecht > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/ZnL336CjCAYJ. 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.