Michael Williams
2007-Feb-19 18:31 UTC
Partials between controllers. . .and one-to-many in practice
Hi all, Question: I have a setup with two entities: Orders and Events. Currently, they''re one-to-one (per the client''s request), but I''ve placed them in separate tables not only because Events have a lot of info, but I foresee it becoming one-to-many. Because I''m using the AjaxScaffold plugin (and don''t wanna give it up, unless, of course, you''ve got a better idea) I need to render a partial from another controller (EventsController) in the ''edit'' of (OrdersController). Is there any simple way to 1) link the other partial in and 2) have the functionality from the EventsController do its part before the OrdersController ? My guess would be to have a lot of code like so in the OrdersController (plural because that''s the way ajax_scaffold does it): def create @order = Order.new(params[:order]) @event = Event.new(params[:event]) $order.event = @event @order.save end . . .but I''m not absolutely sure, and I''d rather know before I go breaking the existing, working, code to refactor the views to support this. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Jason Roelofs
2007-Feb-19 19:46 UTC
Re: Partials between controllers. . .and one-to-many in practice
render :partial => ''/event/edit'' When the path starts with "/", Rails will start at app/views, allowing you to access whatever controller''s views you want. As for running code in the EventsController, that is not possible outside of straight redirecting to that action. Sounds like you are getting some duplicate code that should be pulled into it''s own class and placed in lib/class_name.rb. Jason On 2/19/07, Michael Williams <gberz3-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > Hi all, > > Question: > > I have a setup with two entities: Orders and Events. Currently, > they''re one-to-one (per the client''s request), but I''ve placed them > in separate tables not only because Events have a lot of info, but I > foresee it becoming one-to-many. Because I''m using the AjaxScaffold > plugin (and don''t wanna give it up, unless, of course, you''ve got a > better idea) I need to render a partial from another controller > (EventsController) in the ''edit'' of (OrdersController). Is there any > simple way to 1) link the other partial in and 2) have the > functionality from the EventsController do its part before the > OrdersController ? > > My guess would be to have a lot of code like so in the > OrdersController (plural because that''s the way ajax_scaffold does it): > > def create > @order = Order.new(params[:order]) > @event = Event.new(params[:event]) > > $order.event = @event > > @order.save > end > > > . . .but I''m not absolutely sure, and I''d rather know before I go > breaking the existing, working, code to refactor the views to support > this. > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
gberz3
2007-Feb-21 22:14 UTC
Re: Partials between controllers. . .and one-to-many in practice
I see. . .thanks! --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---