Hey guys, I''m trying to build an app that''s supposed to use 2 controller "collections" if you will. Basically say I want to have a site like http://site/shop (where I show some info) http://site/admin (to manage the products) However, I try to use the generate scaffold script and would like all of the functionality it''s providing right now but for certain tables. Let''s say I have a table called Products, if I generate scaffold product I will get a file called products_controller.rb. This file would have 5 or 6 actions on it, but I would like to be able to access these actions without copy pasting the code to my original controller (shop_controller.rb). I''ve tried something like: require ''products_controller.rb'' but I keep getting this error: undefined method `[]'' for nil:NilClass /app/controllers/products_controller.rb:3:in `list_product'' app/controllers/shop_controller.rb:8:in `index'' script/server:48 The list_product action in products_controller is the standard scaffold action. Someone please help me on this Thanks, Juan
AFAIK scaffolds aren''t meant for generic purpose forms... but more for allowing an easy way to get data into the system so that you can take functionality out of them and place them into more tight knit controllers. Also for testing purposes to ensure that you have AR setup to work with the controllers. I would suggest mimicking functionality into those controllers. Jake Juan Roberto Morales wrote:>Hey guys, I''m trying to build an app that''s supposed to use 2 >controller "collections" if you will. Basically say I want to have a >site like >http://site/shop (where I show some info) >http://site/admin (to manage the products) > >However, I try to use the generate scaffold script and would like all >of the functionality it''s providing right now but for certain tables. >Let''s say I have a table called Products, if I generate scaffold >product I will get a file called products_controller.rb. This file >would have 5 or 6 actions on it, but I would like to be able to access >these actions without copy pasting the code to my original controller >(shop_controller.rb). > >I''ve tried something like: require ''products_controller.rb'' but I >keep getting this error: > >undefined method `[]'' for nil:NilClass > >/app/controllers/products_controller.rb:3:in `list_product'' >app/controllers/shop_controller.rb:8:in `index'' >script/server:48 > >The list_product action in products_controller is the standard scaffold action. > >Someone please help me on this > >Thanks, >Juan >_______________________________________________ >Rails mailing list >Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >http://lists.rubyonrails.org/mailman/listinfo/rails > > >
You kind of have two options here try going scaffold :product in the controller you want to use it on. however this gives you little to no interaction to whats going on when anything is touched/created/deleted or what not. your NOT required to have a controller for every model/scaffold, and your NOT required to use the 6 methods (actions) that scaffold produces for you. On 8/12/05, Juan Roberto Morales <dvstudios-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hey guys, I''m trying to build an app that''s supposed to use 2 > controller "collections" if you will. Basically say I want to have a > site like > http://site/shop (where I show some info) > http://site/admin (to manage the products) > > However, I try to use the generate scaffold script and would like all > of the functionality it''s providing right now but for certain tables. > Let''s say I have a table called Products, if I generate scaffold > product I will get a file called products_controller.rb. This file > would have 5 or 6 actions on it, but I would like to be able to access > these actions without copy pasting the code to my original controller > (shop_controller.rb). > > I''ve tried something like: require ''products_controller.rb'' but I > keep getting this error: > > undefined method `[]'' for nil:NilClass > > /app/controllers/products_controller.rb:3:in `list_product'' > app/controllers/shop_controller.rb:8:in `index'' > script/server:48 > > The list_product action in products_controller is the standard scaffold action. > > Someone please help me on this > > Thanks, > Juan > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Zachery Hostens <zacheryph-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
My idea for this is that if I set up the controllers so that I''m able to call upon them depending on the functionality that I want the "main" controller to have. Is it possible to do this using helpers? modules? On 8/12/05, Jake Good <jake-UDG8+2NMCBIv34k0vaUUyg@public.gmane.org> wrote:> AFAIK scaffolds aren''t meant for generic purpose forms... but more for > allowing an easy way to get data into the system so that you can take > functionality out of them and place them into more tight knit > controllers. Also for testing purposes to ensure that you have AR setup > to work with the controllers. > > I would suggest mimicking functionality into those controllers. > > Jake > > Juan Roberto Morales wrote: > > >Hey guys, I''m trying to build an app that''s supposed to use 2 > >controller "collections" if you will. Basically say I want to have a > >site like > >http://site/shop (where I show some info) > >http://site/admin (to manage the products) > > > >However, I try to use the generate scaffold script and would like all > >of the functionality it''s providing right now but for certain tables. > >Let''s say I have a table called Products, if I generate scaffold > >product I will get a file called products_controller.rb. This file > >would have 5 or 6 actions on it, but I would like to be able to access > >these actions without copy pasting the code to my original controller > >(shop_controller.rb). > > > >I''ve tried something like: require ''products_controller.rb'' but I > >keep getting this error: > > > >undefined method `[]'' for nil:NilClass > > > >/app/controllers/products_controller.rb:3:in `list_product'' > >app/controllers/shop_controller.rb:8:in `index'' > >script/server:48 > > > >The list_product action in products_controller is the standard scaffold action. > > > >Someone please help me on this > > > >Thanks, > >Juan > >_______________________________________________ > >Rails mailing list > >Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > >http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Saludos, Juan Roberto Morales Gerente General Digital Vision Studios
I think helpers would be what you''re looking for... good call. Sounds like you have some abstract functionality that you wan''t across the controllers and that would be a good suggestion. Jake Juan Roberto Morales wrote:>My idea for this is that if I set up the controllers so that I''m able >to call upon them depending on the functionality that I want the >"main" controller to have. > >Is it possible to do this using helpers? modules? > >On 8/12/05, Jake Good <jake-UDG8+2NMCBIv34k0vaUUyg@public.gmane.org> wrote: > > >>AFAIK scaffolds aren''t meant for generic purpose forms... but more for >>allowing an easy way to get data into the system so that you can take >>functionality out of them and place them into more tight knit >>controllers. Also for testing purposes to ensure that you have AR setup >>to work with the controllers. >> >>I would suggest mimicking functionality into those controllers. >> >>Jake >> >>Juan Roberto Morales wrote: >> >> >> >>>Hey guys, I''m trying to build an app that''s supposed to use 2 >>>controller "collections" if you will. Basically say I want to have a >>>site like >>>http://site/shop (where I show some info) >>>http://site/admin (to manage the products) >>> >>>However, I try to use the generate scaffold script and would like all >>>of the functionality it''s providing right now but for certain tables. >>>Let''s say I have a table called Products, if I generate scaffold >>>product I will get a file called products_controller.rb. This file >>>would have 5 or 6 actions on it, but I would like to be able to access >>>these actions without copy pasting the code to my original controller >>>(shop_controller.rb). >>> >>>I''ve tried something like: require ''products_controller.rb'' but I >>>keep getting this error: >>> >>>undefined method `[]'' for nil:NilClass >>> >>>/app/controllers/products_controller.rb:3:in `list_product'' >>>app/controllers/shop_controller.rb:8:in `index'' >>>script/server:48 >>> >>>The list_product action in products_controller is the standard scaffold action. >>> >>>Someone please help me on this >>> >>>Thanks, >>>Juan >>>_______________________________________________ >>>Rails mailing list >>>Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >>>http://lists.rubyonrails.org/mailman/listinfo/rails >>> >>> >>> >>> >>> >>_______________________________________________ >>Rails mailing list >>Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >>http://lists.rubyonrails.org/mailman/listinfo/rails >> >> >> > > > >
I tried copy pasting all the methods into the "main" controller, and it works that way but I''m trying to keep to the Object Orientation. the scaffold :product line works, but as you said I would have no control... maybe I can set it up as a class or something? On 8/12/05, Zachery Hostens <zacheryph-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> You kind of have two options here > > try going > > scaffold :product > > in the controller you want to use it on. however this gives you > little to no interaction to whats going on when anything is > touched/created/deleted or what not. > > your NOT required to have a controller for every model/scaffold, and > your NOT required to use the 6 methods (actions) that scaffold > produces for you. > > > On 8/12/05, Juan Roberto Morales <dvstudios-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Hey guys, I''m trying to build an app that''s supposed to use 2 > > controller "collections" if you will. Basically say I want to have a > > site like > > http://site/shop (where I show some info) > > http://site/admin (to manage the products) > > > > However, I try to use the generate scaffold script and would like all > > of the functionality it''s providing right now but for certain tables. > > Let''s say I have a table called Products, if I generate scaffold > > product I will get a file called products_controller.rb. This file > > would have 5 or 6 actions on it, but I would like to be able to access > > these actions without copy pasting the code to my original controller > > (shop_controller.rb). > > > > I''ve tried something like: require ''products_controller.rb'' but I > > keep getting this error: > > > > undefined method `[]'' for nil:NilClass > > > > /app/controllers/products_controller.rb:3:in `list_product'' > > app/controllers/shop_controller.rb:8:in `index'' > > script/server:48 > > > > The list_product action in products_controller is the standard scaffold action. > > > > Someone please help me on this > > > > Thanks, > > Juan > > _______________________________________________ > > Rails mailing list > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > -- > Zachery Hostens <zacheryph-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Saludos, Juan Roberto Morales Gerente General Digital Vision Studios
I would recommend not doing any of the above. the model should do all validations on its own. and i dont see why you would have 20 different controllers saving one kind of model. your trying to turn 2 lines of code into .... well 2 lines of code. putting data into a model is 1 single line of code, and pulling data out is one line of code, same for a view. saving a model is one line of code. i dont see what your abstracting. I think your trying to do something you shouldnt be, and/or implementing stuff in the wrong places. On 8/12/05, Juan Roberto Morales <dvstudios-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I tried copy pasting all the methods into the "main" controller, and > it works that way but I''m trying to keep to the Object Orientation. > > the scaffold :product line works, but as you said I would have no control... > > maybe I can set it up as a class or something? > > On 8/12/05, Zachery Hostens <zacheryph-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > You kind of have two options here > > > > try going > > > > scaffold :product > > > > in the controller you want to use it on. however this gives you > > little to no interaction to whats going on when anything is > > touched/created/deleted or what not. > > > > your NOT required to have a controller for every model/scaffold, and > > your NOT required to use the 6 methods (actions) that scaffold > > produces for you. > > > > > > On 8/12/05, Juan Roberto Morales <dvstudios-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Hey guys, I''m trying to build an app that''s supposed to use 2 > > > controller "collections" if you will. Basically say I want to have a > > > site like > > > http://site/shop (where I show some info) > > > http://site/admin (to manage the products) > > > > > > However, I try to use the generate scaffold script and would like all > > > of the functionality it''s providing right now but for certain tables. > > > Let''s say I have a table called Products, if I generate scaffold > > > product I will get a file called products_controller.rb. This file > > > would have 5 or 6 actions on it, but I would like to be able to access > > > these actions without copy pasting the code to my original controller > > > (shop_controller.rb). > > > > > > I''ve tried something like: require ''products_controller.rb'' but I > > > keep getting this error: > > > > > > undefined method `[]'' for nil:NilClass > > > > > > /app/controllers/products_controller.rb:3:in `list_product'' > > > app/controllers/shop_controller.rb:8:in `index'' > > > script/server:48 > > > > > > The list_product action in products_controller is the standard scaffold action. > > > > > > Someone please help me on this > > > > > > Thanks, > > > Juan > > > _______________________________________________ > > > Rails mailing list > > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > > > > -- > > Zachery Hostens <zacheryph-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > _______________________________________________ > > Rails mailing list > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > -- > Saludos, > Juan Roberto Morales > Gerente General > Digital Vision Studios > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Zachery Hostens <zacheryph-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Addon: as for trying to have multiple places using the same form to save data, THIS is why they invented partials. On 8/12/05, Zachery Hostens <zacheryph-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I would recommend not doing any of the above. > > the model should do all validations on its own. and i dont see why > you would have 20 different controllers saving one kind of model. > your trying to turn 2 lines of code into .... well 2 lines of code. > > putting data into a model is 1 single line of code, and pulling data > out is one line of code, same for a view. saving a model is one line > of code. i dont see what your abstracting. > > I think your trying to do something you shouldnt be, and/or > implementing stuff in the wrong places. > > > On 8/12/05, Juan Roberto Morales <dvstudios-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > I tried copy pasting all the methods into the "main" controller, and > > it works that way but I''m trying to keep to the Object Orientation. > > > > the scaffold :product line works, but as you said I would have no control... > > > > maybe I can set it up as a class or something? > > > > On 8/12/05, Zachery Hostens <zacheryph-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > You kind of have two options here > > > > > > try going > > > > > > scaffold :product > > > > > > in the controller you want to use it on. however this gives you > > > little to no interaction to whats going on when anything is > > > touched/created/deleted or what not. > > > > > > your NOT required to have a controller for every model/scaffold, and > > > your NOT required to use the 6 methods (actions) that scaffold > > > produces for you. > > > > > > > > > On 8/12/05, Juan Roberto Morales <dvstudios-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Hey guys, I''m trying to build an app that''s supposed to use 2 > > > > controller "collections" if you will. Basically say I want to have a > > > > site like > > > > http://site/shop (where I show some info) > > > > http://site/admin (to manage the products) > > > > > > > > However, I try to use the generate scaffold script and would like all > > > > of the functionality it''s providing right now but for certain tables. > > > > Let''s say I have a table called Products, if I generate scaffold > > > > product I will get a file called products_controller.rb. This file > > > > would have 5 or 6 actions on it, but I would like to be able to access > > > > these actions without copy pasting the code to my original controller > > > > (shop_controller.rb). > > > > > > > > I''ve tried something like: require ''products_controller.rb'' but I > > > > keep getting this error: > > > > > > > > undefined method `[]'' for nil:NilClass > > > > > > > > /app/controllers/products_controller.rb:3:in `list_product'' > > > > app/controllers/shop_controller.rb:8:in `index'' > > > > script/server:48 > > > > > > > > The list_product action in products_controller is the standard scaffold action. > > > > > > > > Someone please help me on this > > > > > > > > Thanks, > > > > Juan > > > > _______________________________________________ > > > > Rails mailing list > > > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > > > > > > > > -- > > > Zachery Hostens <zacheryph-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > > _______________________________________________ > > > Rails mailing list > > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > > > > -- > > Saludos, > > Juan Roberto Morales > > Gerente General > > Digital Vision Studios > > _______________________________________________ > > Rails mailing list > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > -- > Zachery Hostens <zacheryph-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> >-- Zachery Hostens <zacheryph-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
>would have 5 or 6 actions on it, but I would like to be able to access >these actions without copy pasting the code to my original controller >(shop_controller.rb). > > >redirect_to :controller => ''shop'', :action => ''a_shop_action''