I have an B2B application where a pretty complex order form needs to be submitted and edited on the admin controller, buyer controller and seller controller with some small differences. How do I make available the edit order methods all controllers? -- 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 -~----------~----~----~----~------~----~------~--~---
Hi Constantin - Why don''t you just have a order_controller.rb that establishes/follows permissions based on whether the user is an admin, buyer or seller? Marc On Mar 22, 6:11 pm, Constantin Gavrilescu <rails-mailing-l...@andreas- s.net> wrote:> I have an B2B application where a pretty complex order form needs to be > submitted and edited on the admin controller, buyer controller and > seller controller with some small differences. > How do I make available the edit order methods all controllers? > > -- > 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-/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 -~----------~----~----~----~------~----~------~--~---
Constantin Gavrilescu
2007-Mar-23 06:52 UTC
Re: DRY - with modules, render_component or.. ?
Marc Love wrote:> Hi Constantin - > > Why don''t you just have a order_controller.rb that establishes/follows > permissions based on whether the user is an admin, buyer or seller?I thought about that, even created the controller, moved all the code in it, but every role needs a different layout. Not only the layout, but additional code needs to be in the controller for edit_order/list_orders actions, code that does not have anything to do with the order, so it would not make any sense to put it in the order_controller. I''m trying to make a module now, called manage_orders, and I''m planning to keep the template files in shared/order/*.rhtml Another alternative would be just to dump the methods into ApplicationController. I am wondering if there is any way that''s more beautiful or elegant to share this common code between controllers. -- 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 -~----------~----~----~----~------~----~------~--~---
The components route was tried but apparently had negative performance
attributes. For this and probably other reasons, Rails Core is not
advocating use of components. However, plugins will fill the same bill.
Any extension you make to ActionController in your plugin will be seen by
all controllers, and it sounds like that''s the only place where you
need to
make changes. The one additional wrinkle is where the template goes. I
recommend putting the template in the plugin tree as well in a views
directory, then changing telling Rails where to find the correct view. You
do that by changing template_root in earlier versions of Rails and by
calling class function prepend_view_path in edge. Here''s an example
(untested, sorry):
class ActionController
prepend_view_path
"#{RAILS_ROOT}/vendor/plugins/my_plugin/lib/app/views"
def new_order
@order = Order.new # should look for template in your
plugin/lib/app/views directory
end
# etc.
end
Hope this helps.
Mike-293 wrote:>
>
> I have an B2B application where a pretty complex order form needs to be
> submitted and edited on the admin controller, buyer controller and
> seller controller with some small differences.
> How do I make available the edit order methods all controllers?
>
> --
> Posted via http://www.ruby-forum.com/.
>
> >
>
>
--
View this message in context:
http://www.nabble.com/DRY---with-modules%2C-render_component-or..---tf3451425.html#a9629098
Sent from the RubyOnRails Users mailing list archive at Nabble.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
-~----------~----~----~----~------~----~------~--~---
Constantin Gavrilescu
2007-Mar-25 19:25 UTC
Re: DRY - with modules, render_component or.. ?
I''ve put the "order actions" in the order_actions.rb file in
the models
directory and I''m including it in the Admin and Customer controllers as
a mixin.
It seems to work.
class AdminController < ApplicationController
require "order_actions"
include OrderActions
end
===order_actions.rb==Module OrderActions
def list_orders
@orders = Order.find(:all)
raise(''test'') #this is never raised; why?
# RENDER IS IGNORED
render :template => ''shared/order/list_orders''
end
end
Steve Ross wrote:> The components route was tried but apparently had negative performance
> attributes. For this and probably other reasons, Rails Core is not
> advocating use of components. However, plugins will fill the same bill.
>
> Any extension you make to ActionController in your plugin will be seen
> by
> all controllers, and it sounds like that''s the only place where
you need
> to
> make changes.
--
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
-~----------~----~----~----~------~----~------~--~---