I am creating a site which just displays comments and person_detail. I am thinking: * Create 2 models: comments & personal_detail corresponding to 2 tables. * 2 controllers: comments_controller & personal_detail_controller. * Create a controller "home", which invokes actions provided by comments_controller & personal_detail_controller, then display info in the home.rhtml. I wonder how scaffolding can simplify the tasks. -- 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 -~----------~----~----~----~------~----~------~--~---
Gary Liang wrote:> I am creating a site which just displays comments and person_detail. > I am thinking: > * Create 2 models: comments & personal_detail corresponding to 2 tables. > * 2 controllers: comments_controller & personal_detail_controller. > * Create a controller "home", which invokes actions provided by > comments_controller & personal_detail_controller, then display info in > the home.rhtml. > > I wonder how scaffolding can simplify the tasks.I also think I can just create a home_controller & 2 models(comments & personal_detail). I am able to display via the actions provied by those 2 models, right? -- 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 -~----------~----~----~----~------~----~------~--~---
I think it would be simpler to stick with the design with a controller for each model (plus a HomeController if you need it). It''s much easier to go with the CRUD method names created automatically by the scaffolding in each controller, than to have one overall controller that handles lots of methods that deal with different models. Shauna -- 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 -~----------~----~----~----~------~----~------~--~---
Shauna wrote:> I think it would be simpler to stick with the design with a controller > for each model (plus a HomeController if you need it). It''s much easier > to go with the CRUD method names created automatically by the > scaffolding in each controller, than to have one overall controller that > handles lots of methods that deal with different models. > > ShaunaSomeone may ask this question. How can I call actions from other controllers in a overall controller? -- 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 -~----------~----~----~----~------~----~------~--~---
Gary Liang wrote:> Someone may ask this question. How can I call actions from other > controllers in a overall controller?I''m not completely sure what you''re asking... Perhaps inheritance? Basically, can a controller call methods from another controller? The short answer is yes. The most logical way would be to use inheritance (I say logical because this is Ruby and you can technically call almost anything from anywhere). Imagine you have an admin controller with several children controllers. E.g... class AdminController < ApplicationController def admin_method ... end end class UsersController < AdminController def users_method ... admin_method ... end end I''d advise you think through your problem space and ask yourself if you really need to do such a thing. Perhaps some of the responsibility should be assigned to your models? -- 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 -~----------~----~----~----~------~----~------~--~---
Daniel Waite wrote:> Gary Liang wrote: >> Someone may ask this question. How can I call actions from other >> controllers in a overall controller? > > I''m not completely sure what you''re asking... Perhaps inheritance? > Basically, can a controller call methods from another controller? The > short answer is yes. > > The most logical way would be to use inheritance (I say logical because > this is Ruby and you can technically call almost anything from > anywhere). Imagine you have an admin controller with several children > controllers. E.g... > > class AdminController < ApplicationController > > def admin_method > ... > end > > end > > class UsersController < AdminController > > def users_method > ... > admin_method > ... > end > > end > > I''d advise you think through your problem space and ask yourself if you > really need to do such a thing. Perhaps some of the responsibility > should be assigned to your models?e.g. class AdminController < ApplicationController UsersController usersController = new .... usersController.action end class UsersController < ApplicationController ....... end How RoR handle this? -- 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 -~----------~----~----~----~------~----~------~--~---
Gary Liang wrote:> e.g. > > class AdminController < ApplicationController > UsersController usersController = new .... > usersController.action > > end > > > class UsersController < ApplicationController > ....... > end > > How RoR handle this?Look into redirect_to, e.g. redirect_to(:controller => ''loans'', :action => ''list'') Shauna -- 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 -~----------~----~----~----~------~----~------~--~---
Shauna wrote:> Gary Liang wrote: >> e.g. >> >> class AdminController < ApplicationController >> UsersController usersController = new .... >> usersController.action >> >> end >> >> >> class UsersController < ApplicationController >> ....... >> end >> >> How RoR handle this? > > Look into redirect_to, e.g. > redirect_to(:controller => ''loans'', :action => ''list'') > > ShaunaThx Shauna. I think redirect_to will trasfer you to another controller, then execute the list action, then stay in loans.rhtml, perhaps? If that is the case, it may not be what I want. The idea is to stay at the same page, but it has ability to access vary actions from other controllers. I am not sure how RoR handle this? -- 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 -~----------~----~----~----~------~----~------~--~---
> If that is the case, it may not be what I want. The idea is to stay at > the same page, but it has ability to access vary actions from other > controllers. I am not sure how RoR handle this?Sound to me like you either: a) Need to push as much logic into the models as you can (see http://weblog.jamisbuck.org/2006/10/18/skinny-controller-fat-model) or b) Want to implement AJAX on the client. -- 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 -~----------~----~----~----~------~----~------~--~---
Andrew Skegg wrote:>> If that is the case, it may not be what I want. The idea is to stay at >> the same page, but it has ability to access vary actions from other >> controllers. I am not sure how RoR handle this? > > Sound to me like you either: > > a) Need to push as much logic into the models as you can (see > http://weblog.jamisbuck.org/2006/10/18/skinny-controller-fat-model) > > or > > b) Want to implement AJAX on the client.class Whatever def self.action ...... end end In this case, I can call Whatever.action inside any controller. That is what I want. -- 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 -~----------~----~----~----~------~----~------~--~---
Gary Liang wrote:> > > e.g. > > class AdminController < ApplicationController > UsersController usersController = new .... > usersController.action > > end > > > class UsersController < ApplicationController > ....... > end > > How RoR handle this? > >You can do that by doing something like this: class UsersController < ApplicationController def user_method end end class AdminController < ApplicationController def admin_method user = UsersController.new retvalue = user.user_method end end but generally I believe the recommended way for "sharing" methods between controllers is to put stuff in application.rb or create a module and mix that in to the controllers that need it. -- Michael Wang --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
e.g. * ruby script/generate scaffolding Users * Create a controller ''Admin'' * class Users def self.list list end def list ...generate by scaffolding... end end * class Admin def list Users.list end end * Inside the Admin.rhtml @admin = Admin.new @admin.list I don''t have a good feeling about this code....... -- 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 -~----------~----~----~----~------~----~------~--~---
It will be easier to discuss solutions if you give us some more details about how you want your app to behave (rather than picking a particular syntax and asking if that syntax can do this or that aspect of what you want). Shauna --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Gary Liang wrote:> Gary Liang wrote: >> I am creating a site which just displays comments and person_detail. >> I am thinking: >> * Create 2 models: comments & personal_detail corresponding to 2 tables. >> * 2 controllers: comments_controller & personal_detail_controller. >> * Create a controller "home", which invokes actions provided by >> comments_controller & personal_detail_controller, then display info in >> the home.rhtml. >> >> I wonder how scaffolding can simplify the tasks. > > I also think I can just create a home_controller & 2 models(comments & > personal_detail). I am able to display via the actions provied by those > 2 models, right?Im a newbie but you dont have controllers for both models you will have to do a lot of rediect_to ''s with hardcoded contoller names and actions keep track of data/view flows. -- 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 -~----------~----~----~----~------~----~------~--~---