I am currently in a brain freeze. I would like to display my pages (dynamically in cms, grabbing title), in the application layout. The yield is: In HAML = yield :sidemenu The problem is that this yield is in the pages MVC. Is there a way to have a view instantiate another view? Obviously the menu only shows when the url is mysite/pages/ since application.html.haml does not know about pages MVC. I hope this makes sense. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Not exactly sure what you''re referring to when you say "in the pages MVC". However, it sounds like you might be trying to render a partial, in the which case you would use: render :partial => "filename.rhtml" Is that what you''re trying to do? On Jan 28, 3:44 pm, tresero <j...-xnFomyZ2uAo4Q++5jOxPmw@public.gmane.org> wrote:> I am currently in a brain freeze. > I would like to display my pages (dynamically in cms, grabbing title), > in the application layout. > The yield is: In HAML > = yield :sidemenu > > The problem is that this yield is in the pages MVC. Is there a way to > have a view instantiate another view? > Obviously the menu only shows when the url is mysite/pages/ since > application.html.haml does not know about pages MVC. > > I hope this makes sense.--~--~---------~--~----~------------~-------~--~----~ 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 is not a partial, in the application view I am calling: = yield :sidemenu sidemenu is defined in pages/show.rhtml I can''t use a partial in a view can I? On Jan 28, 3:29 pm, Matt White <whit...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Not exactly sure what you''re referring to when you say "in the pages > MVC". However, it sounds like you might be trying to render a partial, > in the which case you would use: > > render :partial => "filename.rhtml" > > Is that what you''re trying to do? > > On Jan 28, 3:44 pm, tresero <j...-xnFomyZ2uAo4Q++5jOxPmw@public.gmane.org> wrote: > > > I am currently in a brain freeze. > > I would like to display my pages (dynamically in cms, grabbing title), > > in the application layout. > > The yield is: In HAML > > = yield :sidemenu > > > The problem is that this yield is in the pages MVC. Is there a way to > > have a view instantiate another view? > > Obviously the menu only shows when the url is mysite/pages/ since > > application.html.haml does not know about pages MVC. > > > I hope this makes sense.--~--~---------~--~----~------------~-------~--~----~ 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 tried this, but it does not use the pages controller, so it errors out. Is there a way to include the pages controller in the main application? On Jan 28, 3:34 pm, tresero <j...-xnFomyZ2uAo4Q++5jOxPmw@public.gmane.org> wrote:> It is not a partial, in the application view I am calling: > = yield :sidemenu > > sidemenu is defined in pages/show.rhtml > > I can''t use a partial in a view can I? > > On Jan 28, 3:29 pm, Matt White <whit...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Not exactly sure what you''re referring to when you say "in the pages > > MVC". However, it sounds like you might be trying to render a partial, > > in the which case you would use: > > > render :partial => "filename.rhtml" > > > Is that what you''re trying to do? > > > On Jan 28, 3:44 pm, tresero <j...-xnFomyZ2uAo4Q++5jOxPmw@public.gmane.org> wrote: > > > > I am currently in a brain freeze. > > > I would like to display my pages (dynamically in cms, grabbing title), > > > in the application layout. > > > The yield is: In HAML > > > = yield :sidemenu > > > > The problem is that this yield is in the pages MVC. Is there a way to > > > have a view instantiate another view? > > > Obviously the menu only shows when the url is mysite/pages/ since > > > application.html.haml does not know about pages MVC. > > > > I hope this makes sense.--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Let me phrase this another way, how can I use data from a specific controller in an application view. I don''t see something like include pages which would gather the pages and pass them to the application.rhtml On Jan 28, 3:39 pm, tresero <j...-xnFomyZ2uAo4Q++5jOxPmw@public.gmane.org> wrote:> I tried this, but it does not use the pages controller, so it errors > out. > Is there a way to include the pages controller in the main > application? > > On Jan 28, 3:34 pm, tresero <j...-xnFomyZ2uAo4Q++5jOxPmw@public.gmane.org> wrote: > > > It is not a partial, in the application view I am calling: > > = yield :sidemenu > > > sidemenu is defined in pages/show.rhtml > > > I can''t use a partial in a view can I? > > > On Jan 28, 3:29 pm, Matt White <whit...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Not exactly sure what you''re referring to when you say "in the pages > > > MVC". However, it sounds like you might be trying to render a partial, > > > in the which case you would use: > > > > render :partial => "filename.rhtml" > > > > Is that what you''re trying to do? > > > > On Jan 28, 3:44 pm, tresero <j...-xnFomyZ2uAo4Q++5jOxPmw@public.gmane.org> wrote: > > > > > I am currently in a brain freeze. > > > > I would like to display my pages (dynamically in cms, grabbing title), > > > > in the application layout. > > > > The yield is: In HAML > > > > = yield :sidemenu > > > > > The problem is that this yield is in the pages MVC. Is there a way to > > > > have a view instantiate another view? > > > > Obviously the menu only shows when the url is mysite/pages/ since > > > > application.html.haml does not know about pages MVC. > > > > > I hope this makes sense.--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
In your pages/show.rhtml <% content_for :heading do -%> <h1>Hey, I''m a Heading!</h1> <% end -%> <ul> <li>I''m a list</li> </ul Then in application.rhtml (or whatever file you call out for the layout): <html> <head><title>Example</title></head> <body> <%= yield :heading %> <p>where''s the list</p> <%= yield %> </body> </html> Will generate: <html> <head><title>Example</title></head> <body> <h1>Hey, I''m a Heading!</h1> <p>where''s the list</p> <ul> <li>I''m a list</li> </ul </body> </html> Is that what you''re trying to understand? -Rob On Jan 28, 2008, at 8:24 PM, tresero wrote:> Let me phrase this another way, how can I use data from a specific > controller in an application view. I don''t see something like include > pages which would gather the pages and pass them to the > application.rhtml > > On Jan 28, 3:39 pm, tresero <j...-xnFomyZ2uAo4Q++5jOxPmw@public.gmane.org> wrote: >> I tried this, but it does not use the pages controller, so it errors >> out. >> Is there a way to include the pages controller in the main >> application? >> >> On Jan 28, 3:34 pm, tresero <j...-xnFomyZ2uAo4Q++5jOxPmw@public.gmane.org> wrote: >> >>> It is not a partial, in the application view I am calling: >>> = yield :sidemenu >> >>> sidemenu is defined in pages/show.rhtml >> >>> I can''t use a partial in a view can I? >> >>> On Jan 28, 3:29 pm, Matt White <whit...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >>>> Not exactly sure what you''re referring to when you say "in the >>>> pages >>>> MVC". However, it sounds like you might be trying to render a >>>> partial, >>>> in the which case you would use: >> >>>> render :partial => "filename.rhtml" >> >>>> Is that what you''re trying to do? >> >>>> On Jan 28, 3:44 pm, tresero <j...-xnFomyZ2uAo4Q++5jOxPmw@public.gmane.org> wrote: >> >>>>> I am currently in a brain freeze. >>>>> I would like to display my pages (dynamically in cms, grabbing >>>>> title), >>>>> in the application layout. >>>>> The yield is: In HAML >>>>> = yield :sidemenu >> >>>>> The problem is that this yield is in the pages MVC. Is there a >>>>> way to >>>>> have a view instantiate another view? >>>>> Obviously the menu only shows when the url is mysite/pages/ since >>>>> application.html.haml does not know about pages MVC. >> >>>>> I hope this makes sense.--~--~---------~--~----~------------~-------~--~----~ 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 get that part, the problem is how to use a model in the "main" template. The sidebar does a query to pull all page titles and display them on the main template. The main template does not know how to deal with pages. Therefor the: - for item in @pages part fails, for obvious reasons. I need a way to get the pages model/ controller logic into the main template. Maybe there is no way, I can alway do raw sql, but I am trying to do it the rails way ;) On Jan 28, 6:00 pm, Rob Biedenharn <R...-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org> wrote:> In your pages/show.rhtml > <% content_for :heading do -%> > <h1>Hey, I''m a Heading!</h1> > <% end -%> > > <ul> > <li>I''m a list</li> > </ul > > Then in application.rhtml (or whatever file you call out for the > layout): > > <html> > <head><title>Example</title></head> > <body> > <%= yield :heading %> > <p>where''s the list</p> > <%= yield %> > </body> > </html> > > Will generate: > > <html> > <head><title>Example</title></head> > <body> > <h1>Hey, I''m a Heading!</h1> > <p>where''s the list</p> > > <ul> > <li>I''m a list</li> > </ul > </body> > </html> > > Is that what you''re trying to understand? > > -Rob > > On Jan 28, 2008, at 8:24 PM, tresero wrote: > > > Let me phrase this another way, how can I use data from a specific > > controller in an application view. I don''t see something like include > > pages which would gather the pages and pass them to the > > application.rhtml > > > On Jan 28, 3:39 pm, tresero <j...-xnFomyZ2uAo4Q++5jOxPmw@public.gmane.org> wrote: > >> I tried this, but it does not use the pages controller, so it errors > >> out. > >> Is there a way to include the pages controller in the main > >> application? > > >> On Jan 28, 3:34 pm, tresero <j...-xnFomyZ2uAo4Q++5jOxPmw@public.gmane.org> wrote: > > >>> It is not a partial, in the application view I am calling: > >>> = yield :sidemenu > > >>> sidemenu is defined in pages/show.rhtml > > >>> I can''t use a partial in a view can I? > > >>> On Jan 28, 3:29 pm, Matt White <whit...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > >>>> Not exactly sure what you''re referring to when you say "in the > >>>> pages > >>>> MVC". However, it sounds like you might be trying to render a > >>>> partial, > >>>> in the which case you would use: > > >>>> render :partial => "filename.rhtml" > > >>>> Is that what you''re trying to do? > > >>>> On Jan 28, 3:44 pm, tresero <j...-xnFomyZ2uAo4Q++5jOxPmw@public.gmane.org> wrote: > > >>>>> I am currently in a brain freeze. > >>>>> I would like to display my pages (dynamically in cms, grabbing > >>>>> title), > >>>>> in the application layout. > >>>>> The yield is: In HAML > >>>>> = yield :sidemenu > > >>>>> The problem is that this yield is in the pages MVC. Is there a > >>>>> way to > >>>>> have a view instantiate another view? > >>>>> Obviously the menu only shows when the url is mysite/pages/ since > >>>>> application.html.haml does not know about pages MVC. > > >>>>> I hope this makes sense.--~--~---------~--~----~------------~-------~--~----~ 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''m not sure I understand what you''re really trying to do, but let me throw this out to you: In your views, avoid having "code". Use the instance variables set by the controller and try to do nothing more than simple tests and loops (@things.each or render :partial => ''...'', :collection => @things) In your controllers, avoid the temptation to put too much code and don''t (DON''T) put any SQL in the controller. If you find yourself putting HTML into a controller method, you probably should be in the view or at least in a helper. In your models, do the heavy lifting, but rest the weight on ActiveRecord associations where you can. Whenever you want to put a :conditions clause on a finder in a controller, go to the model and put a new method that does exactly what you need. You were writing tests, right? Seriously, try to have a test for every bit of your code that isn''t so trivial that it couldn''t possibly break. (Take careful note that the definitions of "trivial" and "...couldn''t possibly..." will vary over time according to the balance between fear and experience -- pay attention to the feedback loop!) -Rob On Jan 29, 2008, at 12:50 AM, tresero wrote:> > I get that part, the problem is how to use a model in the "main" > template. The sidebar does a query to pull all page titles and display > them on the main template. > The main template does not know how to deal with pages. Therefor the: > - for item in @pages > part fails, for obvious reasons. I need a way to get the pages model/ > controller logic into the main template. > Maybe there is no way, I can alway do raw sql, but I am trying to do > it the rails way ;) > > > On Jan 28, 6:00 pm, Rob Biedenharn <R...-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org> > wrote: >> In your pages/show.rhtml >> <% content_for :heading do -%> >> <h1>Hey, I''m a Heading!</h1> >> <% end -%> >> >> <ul> >> <li>I''m a list</li> >> </ul >> >> Then in application.rhtml (or whatever file you call out for the >> layout): >> >> <html> >> <head><title>Example</title></head> >> <body> >> <%= yield :heading %> >> <p>where''s the list</p> >> <%= yield %> >> </body> >> </html> >> >> Will generate: >> >> <html> >> <head><title>Example</title></head> >> <body> >> <h1>Hey, I''m a Heading!</h1> >> <p>where''s the list</p> >> >> <ul> >> <li>I''m a list</li> >> </ul >> </body> >> </html> >> >> Is that what you''re trying to understand? >> >> -Rob >> >> On Jan 28, 2008, at 8:24 PM, tresero wrote: >> >>> Let me phrase this another way, how can I use data from a specific >>> controller in an application view. I don''t see something like >>> include >>> pages which would gather the pages and pass them to the >>> application.rhtml >> >>> On Jan 28, 3:39 pm, tresero <j...-xnFomyZ2uAo4Q++5jOxPmw@public.gmane.org> wrote: >>>> I tried this, but it does not use the pages controller, so it >>>> errors >>>> out. >>>> Is there a way to include the pages controller in the main >>>> application? >> >>>> On Jan 28, 3:34 pm, tresero <j...-xnFomyZ2uAo4Q++5jOxPmw@public.gmane.org> wrote: >> >>>>> It is not a partial, in the application view I am calling: >>>>> = yield :sidemenu >> >>>>> sidemenu is defined in pages/show.rhtml >> >>>>> I can''t use a partial in a view can I? >> >>>>> On Jan 28, 3:29 pm, Matt White <whit...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >>>>>> Not exactly sure what you''re referring to when you say "in the >>>>>> pages >>>>>> MVC". However, it sounds like you might be trying to render a >>>>>> partial, >>>>>> in the which case you would use: >> >>>>>> render :partial => "filename.rhtml" >> >>>>>> Is that what you''re trying to do? >> >>>>>> On Jan 28, 3:44 pm, tresero <j...-xnFomyZ2uAo4Q++5jOxPmw@public.gmane.org> wrote: >> >>>>>>> I am currently in a brain freeze. >>>>>>> I would like to display my pages (dynamically in cms, grabbing >>>>>>> title), >>>>>>> in the application layout. >>>>>>> The yield is: In HAML >>>>>>> = yield :sidemenu >> >>>>>>> The problem is that this yield is in the pages MVC. Is there a >>>>>>> way to >>>>>>> have a view instantiate another view? >>>>>>> Obviously the menu only shows when the url is mysite/pages/ >>>>>>> since >>>>>>> application.html.haml does not know about pages MVC. >> >>>>>>> I hope this makes sense. > >Rob Biedenharn http://agileconsultingllc.com Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org +1 513-295-4739 Skype: rob.biedenharn --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Amen! On Jan 29, 1:12 am, Rob Biedenharn <R...-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org> wrote:> I''m not sure I understand what you''re really trying to do, but let me > throw this out to you: > > In your views, avoid having "code". Use the instance variables set by > the controller and try to do nothing more than simple tests and loops > (@things.each or render :partial => ''...'', :collection => @things) > > In your controllers, avoid the temptation to put too much code and > don''t (DON''T) put any SQL in the controller. If you find yourself > putting HTML into a controller method, you probably should be in the > view or at least in a helper. > > In your models, do the heavy lifting, but rest the weight on > ActiveRecord associations where you can. Whenever you want to put > a :conditions clause on a finder in a controller, go to the model and > put a new method that does exactly what you need. > > You were writing tests, right? Seriously, try to have a test for > every bit of your code that isn''t so trivial that it couldn''t possibly > break. (Take careful note that the definitions of "trivial" and > "...couldn''t possibly..." will vary over time according to the balance > between fear and experience -- pay attention to the feedback loop!) > > -Rob > > On Jan 29, 2008, at 12:50 AM, tresero wrote: > > > > > > > I get that part, the problem is how to use a model in the "main" > > template. The sidebar does a query to pull all page titles and display > > them on the main template. > > The main template does not know how to deal with pages. Therefor the: > > - for item in @pages > > part fails, for obvious reasons. I need a way to get the pages model/ > > controller logic into the main template. > > Maybe there is no way, I can alway do raw sql, but I am trying to do > > it the rails way ;) > > > On Jan 28, 6:00 pm, Rob Biedenharn <R...-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org> > > wrote: > >> In your pages/show.rhtml > >> <% content_for :heading do -%> > >> <h1>Hey, I''m a Heading!</h1> > >> <% end -%> > > >> <ul> > >> <li>I''m a list</li> > >> </ul > > >> Then in application.rhtml (or whatever file you call out for the > >> layout): > > >> <html> > >> <head><title>Example</title></head> > >> <body> > >> <%= yield :heading %> > >> <p>where''s the list</p> > >> <%= yield %> > >> </body> > >> </html> > > >> Will generate: > > >> <html> > >> <head><title>Example</title></head> > >> <body> > >> <h1>Hey, I''m a Heading!</h1> > >> <p>where''s the list</p> > > >> <ul> > >> <li>I''m a list</li> > >> </ul > >> </body> > >> </html> > > >> Is that what you''re trying to understand? > > >> -Rob > > >> On Jan 28, 2008, at 8:24 PM, tresero wrote: > > >>> Let me phrase this another way, how can I use data from a specific > >>> controller in an application view. I don''t see something like > >>> include > >>> pages which would gather the pages and pass them to the > >>> application.rhtml > > >>> On Jan 28, 3:39 pm, tresero <j...-xnFomyZ2uAo4Q++5jOxPmw@public.gmane.org> wrote: > >>>> I tried this, but it does not use the pages controller, so it > >>>> errors > >>>> out. > >>>> Is there a way to include the pages controller in the main > >>>> application? > > >>>> On Jan 28, 3:34 pm, tresero <j...-xnFomyZ2uAo4Q++5jOxPmw@public.gmane.org> wrote: > > >>>>> It is not a partial, in the application view I am calling: > >>>>> = yield :sidemenu > > >>>>> sidemenu is defined in pages/show.rhtml > > >>>>> I can''t use a partial in a view can I? > > >>>>> On Jan 28, 3:29 pm, Matt White <whit...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > >>>>>> Not exactly sure what you''re referring to when you say "in the > >>>>>> pages > >>>>>> MVC". However, it sounds like you might be trying to render a > >>>>>> partial, > >>>>>> in the which case you would use: > > >>>>>> render :partial => "filename.rhtml" > > >>>>>> Is that what you''re trying to do? > > >>>>>> On Jan 28, 3:44 pm, tresero <j...-xnFomyZ2uAo4Q++5jOxPmw@public.gmane.org> wrote: > > >>>>>>> I am currently in a brain freeze. > >>>>>>> I would like to display my pages (dynamically in cms, grabbing > >>>>>>> title), > >>>>>>> in the application layout. > >>>>>>> The yield is: In HAML > >>>>>>> = yield :sidemenu > > >>>>>>> The problem is that this yield is in the pages MVC. Is there a > >>>>>>> way to > >>>>>>> have a view instantiate another view? > >>>>>>> Obviously the menu only shows when the url is mysite/pages/ > >>>>>>> since > >>>>>>> application.html.haml does not know about pages MVC. > > >>>>>>> I hope this makes sense. > > Rob Biedenharn http://agileconsultingllc.com > R...-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org > +1 513-295-4739 > Skype: rob.biedenharn--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Rob, Thanks for the info, but this is not testing. Let me see if I can explain it another way with a different scenario (and I could be doing this completely wrong in my thinking). I have a site, one component is a blog, so there is a blog model, controller and view. I also have an application view which is the main view on the whole site. If I wanted to get a random blog headline on the site, how would I go about doing it? If I am not on a blog url, application does not know how to get at the data. So I hope that makes more sense. I am thinking I need to do some query in controllers/application.rb. I was hoping to make it DRY and not repeat the code from blog.rb. Thanks Jon On Jan 28, 10:12 pm, Rob Biedenharn <R...-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org> wrote:> I''m not sure I understand what you''re really trying to do, but let me > throw this out to you: > > In your views, avoid having "code". Use the instance variables set by > the controller and try to do nothing more than simple tests and loops > (@things.each or render :partial => ''...'', :collection => @things) > > In your controllers, avoid the temptation to put too much code and > don''t (DON''T) put any SQL in the controller. If you find yourself > putting HTML into a controller method, you probably should be in the > view or at least in a helper. > > In your models, do the heavy lifting, but rest the weight on > ActiveRecord associations where you can. Whenever you want to put > a :conditions clause on a finder in a controller, go to the model and > put a new method that does exactly what you need. > > You were writing tests, right? Seriously, try to have a test for > every bit of your code that isn''t so trivial that it couldn''t possibly > break. (Take careful note that the definitions of "trivial" and > "...couldn''t possibly..." will vary over time according to the balance > between fear and experience -- pay attention to the feedback loop!) > > -Rob > > On Jan 29, 2008, at 12:50 AM, tresero wrote: > > > > > > > I get that part, the problem is how to use a model in the "main" > > template. The sidebar does a query to pull all page titles and display > > them on the main template. > > The main template does not know how to deal with pages. Therefor the: > > - for item in @pages > > part fails, for obvious reasons. I need a way to get the pages model/ > > controller logic into the main template. > > Maybe there is no way, I can alway do raw sql, but I am trying to do > > it the rails way ;) > > > On Jan 28, 6:00 pm, Rob Biedenharn <R...-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org> > > wrote: > >> In your pages/show.rhtml > >> <% content_for :heading do -%> > >> <h1>Hey, I''m a Heading!</h1> > >> <% end -%> > > >> <ul> > >> <li>I''m a list</li> > >> </ul > > >> Then in application.rhtml (or whatever file you call out for the > >> layout): > > >> <html> > >> <head><title>Example</title></head> > >> <body> > >> <%= yield :heading %> > >> <p>where''s the list</p> > >> <%= yield %> > >> </body> > >> </html> > > >> Will generate: > > >> <html> > >> <head><title>Example</title></head> > >> <body> > >> <h1>Hey, I''m a Heading!</h1> > >> <p>where''s the list</p> > > >> <ul> > >> <li>I''m a list</li> > >> </ul > >> </body> > >> </html> > > >> Is that what you''re trying to understand? > > >> -Rob > > >> On Jan 28, 2008, at 8:24 PM, tresero wrote: > > >>> Let me phrase this another way, how can I use data from a specific > >>> controller in an application view. I don''t see something like > >>> include > >>> pages which would gather the pages and pass them to the > >>> application.rhtml > > >>> On Jan 28, 3:39 pm, tresero <j...-xnFomyZ2uAo4Q++5jOxPmw@public.gmane.org> wrote: > >>>> I tried this, but it does not use the pages controller, so it > >>>> errors > >>>> out. > >>>> Is there a way to include the pages controller in the main > >>>> application? > > >>>> On Jan 28, 3:34 pm, tresero <j...-xnFomyZ2uAo4Q++5jOxPmw@public.gmane.org> wrote: > > >>>>> It is not a partial, in the application view I am calling: > >>>>> = yield :sidemenu > > >>>>> sidemenu is defined in pages/show.rhtml > > >>>>> I can''t use a partial in a view can I? > > >>>>> On Jan 28, 3:29 pm, Matt White <whit...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > >>>>>> Not exactly sure what you''re referring to when you say "in the > >>>>>> pages > >>>>>> MVC". However, it sounds like you might be trying to render a > >>>>>> partial, > >>>>>> in the which case you would use: > > >>>>>> render :partial => "filename.rhtml" > > >>>>>> Is that what you''re trying to do? > > >>>>>> On Jan 28, 3:44 pm, tresero <j...-xnFomyZ2uAo4Q++5jOxPmw@public.gmane.org> wrote: > > >>>>>>> I am currently in a brain freeze. > >>>>>>> I would like to display my pages (dynamically in cms, grabbing > >>>>>>> title), > >>>>>>> in the application layout. > >>>>>>> The yield is: In HAML > >>>>>>> = yield :sidemenu > > >>>>>>> The problem is that this yield is in the pages MVC. Is there a > >>>>>>> way to > >>>>>>> have a view instantiate another view? > >>>>>>> Obviously the menu only shows when the url is mysite/pages/ > >>>>>>> since > >>>>>>> application.html.haml does not know about pages MVC. > > >>>>>>> I hope this makes sense. > > Rob Biedenharn http://agileconsultingllc.com > R...-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org > +1 513-295-4739 > Skype: rob.biedenharn--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Jan 29, 2008, at 11:28 AM, tresero wrote:> Rob, > Thanks for the info, but this is not testing. > Let me see if I can explain it another way with a different scenario > (and I could be doing this completely wrong in my thinking). > I have a site, one component is a blog, so there is a blog model,...So there''s a Blog.headlines that returns an array of headlines (or Blog.headlines(n) to get the most recent n headlines)> > controller and view. I also have an application view which is the main > view on the whole site. > If I wanted to get a random blog headline on the site, how would I go > about doing it? If I am not on a blog url, application does not know > how to get at the data.That controller calls Blog.random_headline (possibly in a before_filter) and the layout incorporates the view for the headline.> > So I hope that makes more sense. I am thinking I need to do some query > in controllers/application.rb. I was hoping to make it DRY and not > repeat the code from blog.rb. > > Thanks > JonIt that becoming clear? -Rob> On Jan 28, 10:12 pm, Rob Biedenharn <R...-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org> > wrote: >> I''m not sure I understand what you''re really trying to do, but let me >> throw this out to you: >> >> In your views, avoid having "code". Use the instance variables set >> by >> the controller and try to do nothing more than simple tests and loops >> (@things.each or render :partial => ''...'', :collection => @things) >> >> In your controllers, avoid the temptation to put too much code and >> don''t (DON''T) put any SQL in the controller. If you find yourself >> putting HTML into a controller method, you probably should be in the >> view or at least in a helper. >> >> In your models, do the heavy lifting, but rest the weight on >> ActiveRecord associations where you can. Whenever you want to put >> a :conditions clause on a finder in a controller, go to the model and >> put a new method that does exactly what you need. >> >> You were writing tests, right? Seriously, try to have a test for >> every bit of your code that isn''t so trivial that it couldn''t >> possibly >> break. (Take careful note that the definitions of "trivial" and >> "...couldn''t possibly..." will vary over time according to the >> balance >> between fear and experience -- pay attention to the feedback loop!) >> >> -Rob >> >> On Jan 29, 2008, at 12:50 AM, tresero wrote: >> >> >> >> >> >>> I get that part, the problem is how to use a model in the "main" >>> template. The sidebar does a query to pull all page titles and >>> display >>> them on the main template. >>> The main template does not know how to deal with pages. Therefor >>> the: >>> - for item in @pages >>> part fails, for obvious reasons. I need a way to get the pages >>> model/ >>> controller logic into the main template. >>> Maybe there is no way, I can alway do raw sql, but I am trying to do >>> it the rails way ;) >> >>> On Jan 28, 6:00 pm, Rob Biedenharn <R...-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org> >>> wrote: >>>> In your pages/show.rhtml >>>> <% content_for :heading do -%> >>>> <h1>Hey, I''m a Heading!</h1> >>>> <% end -%> >> >>>> <ul> >>>> <li>I''m a list</li> >>>> </ul >> >>>> Then in application.rhtml (or whatever file you call out for the >>>> layout): >> >>>> <html> >>>> <head><title>Example</title></head> >>>> <body> >>>> <%= yield :heading %> >>>> <p>where''s the list</p> >>>> <%= yield %> >>>> </body> >>>> </html> >> >>>> Will generate: >> >>>> <html> >>>> <head><title>Example</title></head> >>>> <body> >>>> <h1>Hey, I''m a Heading!</h1> >>>> <p>where''s the list</p> >> >>>> <ul> >>>> <li>I''m a list</li> >>>> </ul >>>> </body> >>>> </html> >> >>>> Is that what you''re trying to understand? >> >>>> -Rob >> >>>> On Jan 28, 2008, at 8:24 PM, tresero wrote: >> >>>>> Let me phrase this another way, how can I use data from a specific >>>>> controller in an application view. I don''t see something like >>>>> include >>>>> pages which would gather the pages and pass them to the >>>>> application.rhtml >> >>>>> On Jan 28, 3:39 pm, tresero <j...-xnFomyZ2uAo4Q++5jOxPmw@public.gmane.org> wrote: >>>>>> I tried this, but it does not use the pages controller, so it >>>>>> errors >>>>>> out. >>>>>> Is there a way to include the pages controller in the main >>>>>> application? >> >>>>>> On Jan 28, 3:34 pm, tresero <j...-xnFomyZ2uAo4Q++5jOxPmw@public.gmane.org> wrote: >> >>>>>>> It is not a partial, in the application view I am calling: >>>>>>> = yield :sidemenu >> >>>>>>> sidemenu is defined in pages/show.rhtml >> >>>>>>> I can''t use a partial in a view can I? >> >>>>>>> On Jan 28, 3:29 pm, Matt White <whit...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >>>>>>>> Not exactly sure what you''re referring to when you say "in the >>>>>>>> pages >>>>>>>> MVC". However, it sounds like you might be trying to render a >>>>>>>> partial, >>>>>>>> in the which case you would use: >> >>>>>>>> render :partial => "filename.rhtml" >> >>>>>>>> Is that what you''re trying to do? >> >>>>>>>> On Jan 28, 3:44 pm, tresero <j...-xnFomyZ2uAo4Q++5jOxPmw@public.gmane.org> wrote: >> >>>>>>>>> I am currently in a brain freeze. >>>>>>>>> I would like to display my pages (dynamically in cms, grabbing >>>>>>>>> title), >>>>>>>>> in the application layout. >>>>>>>>> The yield is: In HAML >>>>>>>>> = yield :sidemenu >> >>>>>>>>> The problem is that this yield is in the pages MVC. Is there a >>>>>>>>> way to >>>>>>>>> have a view instantiate another view? >>>>>>>>> Obviously the menu only shows when the url is mysite/pages/ >>>>>>>>> since >>>>>>>>> application.html.haml does not know about pages MVC. >> >>>>>>>>> I hope this makes sense. >> >>Rob Biedenharn http://agileconsultingllc.com Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Yes, I believe so. I guess I have to put this in the controllers/ application.rb. I will look at it tonight and let you know. Thanks On Jan 29, 8:53 am, Rob Biedenharn <R...-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org> wrote:> On Jan 29, 2008, at 11:28 AM, tresero wrote: > > > Rob, > > Thanks for the info, but this is not testing. > > Let me see if I can explain it another way with a different scenario > > (and I could be doing this completely wrong in my thinking). > > I have a site, one component is a blog, so there is a blog model, > > ...So there''s a Blog.headlines that returns an array of headlines (or > Blog.headlines(n) to get the most recent n headlines) > > > > > controller and view. I also have an application view which is the main > > view on the whole site. > > If I wanted to get a random blog headline on the site, how would I go > > about doing it? If I am not on a blog url, application does not know > > how to get at the data. > > That controller calls Blog.random_headline (possibly in a > before_filter) and the layout incorporates the view for the headline. > > > > > So I hope that makes more sense. I am thinking I need to do some query > > in controllers/application.rb. I was hoping to make it DRY and not > > repeat the code from blog.rb. > > > Thanks > > Jon > > It that becoming clear? > -Rob > > > > > On Jan 28, 10:12 pm, Rob Biedenharn <R...-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org> > > wrote: > >> I''m not sure I understand what you''re really trying to do, but let me > >> throw this out to you: > > >> In your views, avoid having "code". Use the instance variables set > >> by > >> the controller and try to do nothing more than simple tests and loops > >> (@things.each or render :partial => ''...'', :collection => @things) > > >> In your controllers, avoid the temptation to put too much code and > >> don''t (DON''T) put any SQL in the controller. If you find yourself > >> putting HTML into a controller method, you probably should be in the > >> view or at least in a helper. > > >> In your models, do the heavy lifting, but rest the weight on > >> ActiveRecord associations where you can. Whenever you want to put > >> a :conditions clause on a finder in a controller, go to the model and > >> put a new method that does exactly what you need. > > >> You were writing tests, right? Seriously, try to have a test for > >> every bit of your code that isn''t so trivial that it couldn''t > >> possibly > >> break. (Take careful note that the definitions of "trivial" and > >> "...couldn''t possibly..." will vary over time according to the > >> balance > >> between fear and experience -- pay attention to the feedback loop!) > > >> -Rob > > >> On Jan 29, 2008, at 12:50 AM, tresero wrote: > > >>> I get that part, the problem is how to use a model in the "main" > >>> template. The sidebar does a query to pull all page titles and > >>> display > >>> them on the main template. > >>> The main template does not know how to deal with pages. Therefor > >>> the: > >>> - for item in @pages > >>> part fails, for obvious reasons. I need a way to get the pages > >>> model/ > >>> controller logic into the main template. > >>> Maybe there is no way, I can alway do raw sql, but I am trying to do > >>> it the rails way ;) > > >>> On Jan 28, 6:00 pm, Rob Biedenharn <R...-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org> > >>> wrote: > >>>> In your pages/show.rhtml > >>>> <% content_for :heading do -%> > >>>> <h1>Hey, I''m a Heading!</h1> > >>>> <% end -%> > > >>>> <ul> > >>>> <li>I''m a list</li> > >>>> </ul > > >>>> Then in application.rhtml (or whatever file you call out for the > >>>> layout): > > >>>> <html> > >>>> <head><title>Example</title></head> > >>>> <body> > >>>> <%= yield :heading %> > >>>> <p>where''s the list</p> > >>>> <%= yield %> > >>>> </body> > >>>> </html> > > >>>> Will generate: > > >>>> <html> > >>>> <head><title>Example</title></head> > >>>> <body> > >>>> <h1>Hey, I''m a Heading!</h1> > >>>> <p>where''s the list</p> > > >>>> <ul> > >>>> <li>I''m a list</li> > >>>> </ul > >>>> </body> > >>>> </html> > > >>>> Is that what you''re trying to understand? > > >>>> -Rob > > >>>> On Jan 28, 2008, at 8:24 PM, tresero wrote: > > >>>>> Let me phrase this another way, how can I use data from a specific > >>>>> controller in an application view. I don''t see something like > >>>>> include > >>>>> pages which would gather the pages and pass them to the > >>>>> application.rhtml > > >>>>> On Jan 28, 3:39 pm, tresero <j...-xnFomyZ2uAo4Q++5jOxPmw@public.gmane.org> wrote: > >>>>>> I tried this, but it does not use the pages controller, so it > >>>>>> errors > >>>>>> out. > >>>>>> Is there a way to include the pages controller in the main > >>>>>> application? > > >>>>>> On Jan 28, 3:34 pm, tresero <j...-xnFomyZ2uAo4Q++5jOxPmw@public.gmane.org> wrote: > > >>>>>>> It is not a partial, in the application view I am calling: > >>>>>>> = yield :sidemenu > > >>>>>>> sidemenu is defined in pages/show.rhtml > > >>>>>>> I can''t use a partial in a view can I? > > >>>>>>> On Jan 28, 3:29 pm, Matt White <whit...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > >>>>>>>> Not exactly sure what you''re referring to when you say "in the > >>>>>>>> pages > >>>>>>>> MVC". However, it sounds like you might be trying to render a > >>>>>>>> partial, > >>>>>>>> in the which case you would use: > > >>>>>>>> render :partial => "filename.rhtml" > > >>>>>>>> Is that what you''re trying to do? > > >>>>>>>> On Jan 28, 3:44 pm, tresero <j...-xnFomyZ2uAo4Q++5jOxPmw@public.gmane.org> wrote: > > >>>>>>>>> I am currently in a brain freeze. > >>>>>>>>> I would like to display my pages (dynamically in cms, grabbing > >>>>>>>>> title), > >>>>>>>>> in the application layout. > >>>>>>>>> The yield is: In HAML > >>>>>>>>> = yield :sidemenu > > >>>>>>>>> The problem is that this yield is in the pages MVC. Is there a > >>>>>>>>> way to > >>>>>>>>> have a view instantiate another view? > >>>>>>>>> Obviously the menu only shows when the url is mysite/pages/ > >>>>>>>>> since > >>>>>>>>> application.html.haml does not know about pages MVC. > > >>>>>>>>> I hope this makes sense. > > Rob Biedenharn http://agileconsultingllc.com > R...-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Tresero, Didn''t have time to read thoroughly, but it seems this paper could help a lot: http://www.railsdev.ws/blog/wp-content/uploads/2007/10/modular_page_assembly_in_rails.pdf Cheers, Sazima On Jan 29, 4:57 pm, tresero <j...-xnFomyZ2uAo4Q++5jOxPmw@public.gmane.org> wrote:> Yes, I believe so. I guess I have to put this in the controllers/ > application.rb. > I will look at it tonight and let you know. > > Thanks > > On Jan 29, 8:53 am, Rob Biedenharn <R...-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org> > wrote: > > > On Jan 29, 2008, at 11:28 AM, tresero wrote: > > > > Rob, > > > Thanks for the info, but this is not testing. > > > Let me see if I can explain it another way with a different scenario > > > (and I could be doing this completely wrong in my thinking). > > > I have a site, one component is a blog, so there is a blog model, > > > ...So there''s a Blog.headlines that returns an array of headlines (or > > Blog.headlines(n) to get the most recent n headlines) > > > > controller and view. I also have an application view which is the main > > > view on the whole site. > > > If I wanted to get a random blog headline on the site, how would I go > > > about doing it? If I am not on a blog url, application does not know > > > how to get at the data. > > > That controller calls Blog.random_headline (possibly in a > > before_filter) and the layout incorporates the view for the headline. > > > > So I hope that makes more sense. I am thinking I need to do some query > > > in controllers/application.rb. I was hoping to make it DRY and not > > > repeat the code from blog.rb. > > > > Thanks > > > Jon > > > It that becoming clear? > > -Rob > > > > On Jan 28, 10:12 pm, Rob Biedenharn <R...-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org> > > > wrote: > > >> I''m not sure I understand what you''re really trying to do, but let me > > >> throw this out to you: > > > >> In your views, avoid having "code". Use the instance variables set > > >> by > > >> the controller and try to do nothing more than simple tests and loops > > >> (@things.each or render :partial => ''...'', :collection => @things) > > > >> In your controllers, avoid the temptation to put too much code and > > >> don''t (DON''T) put any SQL in the controller. If you find yourself > > >> putting HTML into a controller method, you probably should be in the > > >> view or at least in a helper. > > > >> In your models, do the heavy lifting, but rest the weight on > > >> ActiveRecord associations where you can. Whenever you want to put > > >> a :conditions clause on a finder in a controller, go to the model and > > >> put a new method that does exactly what you need. > > > >> You were writing tests, right? Seriously, try to have a test for > > >> every bit of your code that isn''t so trivial that it couldn''t > > >> possibly > > >> break. (Take careful note that the definitions of "trivial" and > > >> "...couldn''t possibly..." will vary over time according to the > > >> balance > > >> between fear and experience -- pay attention to the feedback loop!) > > > >> -Rob > > > >> On Jan 29, 2008, at 12:50 AM, tresero wrote: > > > >>> I get that part, the problem is how to use a model in the "main" > > >>> template. The sidebar does a query to pull all page titles and > > >>> display > > >>> them on the main template. > > >>> The main template does not know how to deal with pages. Therefor > > >>> the: > > >>> - for item in @pages > > >>> part fails, for obvious reasons. I need a way to get the pages > > >>> model/ > > >>> controller logic into the main template. > > >>> Maybe there is no way, I can alway do raw sql, but I am trying to do > > >>> it the rails way ;) > > > >>> On Jan 28, 6:00 pm, Rob Biedenharn <R...-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org> > > >>> wrote: > > >>>> In your pages/show.rhtml > > >>>> <% content_for :heading do -%> > > >>>> <h1>Hey, I''m a Heading!</h1> > > >>>> <% end -%> > > > >>>> <ul> > > >>>> <li>I''m a list</li> > > >>>> </ul > > > >>>> Then in application.rhtml (or whatever file you call out for the > > >>>> layout): > > > >>>> <html> > > >>>> <head><title>Example</title></head> > > >>>> <body> > > >>>> <%= yield :heading %> > > >>>> <p>where''s the list</p> > > >>>> <%= yield %> > > >>>> </body> > > >>>> </html> > > > >>>> Will generate: > > > >>>> <html> > > >>>> <head><title>Example</title></head> > > >>>> <body> > > >>>> <h1>Hey, I''m a Heading!</h1> > > >>>> <p>where''s the list</p> > > > >>>> <ul> > > >>>> <li>I''m a list</li> > > >>>> </ul > > >>>> </body> > > >>>> </html> > > > >>>> Is that what you''re trying to understand? > > > >>>> -Rob > > > >>>> On Jan 28, 2008, at 8:24 PM, tresero wrote: > > > >>>>> Let me phrase this another way, how can I use data from a specific > > >>>>> controller in an application view. I don''t see something like > > >>>>> include > > >>>>> pages which would gather the pages and pass them to the > > >>>>> application.rhtml > > > >>>>> On Jan 28, 3:39 pm, tresero <j...-xnFomyZ2uAo4Q++5jOxPmw@public.gmane.org> wrote: > > >>>>>> I tried this, but it does not use the pages controller, so it > > >>>>>> errors > > >>>>>> out. > > >>>>>> Is there a way to include the pages controller in the main > > >>>>>> application? > > > >>>>>> On Jan 28, 3:34 pm, tresero <j...-xnFomyZ2uAo4Q++5jOxPmw@public.gmane.org> wrote: > > > >>>>>>> It is not a partial, in the application view I am calling: > > >>>>>>> = yield :sidemenu > > > >>>>>>> sidemenu is defined in pages/show.rhtml > > > >>>>>>> I can''t use a partial in a view can I? > > > >>>>>>> On Jan 28, 3:29 pm, Matt White <whit...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > >>>>>>>> Not exactly sure what you''re referring to when you say "in the > > >>>>>>>> pages > > >>>>>>>> MVC". However, it sounds like you might be trying to render a > > >>>>>>>> partial, > > >>>>>>>> in the which case you would use: > > > >>>>>>>> render :partial => "filename.rhtml" > > > >>>>>>>> Is that what you''re trying to do? > > > >>>>>>>> On Jan 28, 3:44 pm, tresero <j...-xnFomyZ2uAo4Q++5jOxPmw@public.gmane.org> wrote: > > > >>>>>>>>> I am currently in a brain freeze. > > >>>>>>>>> I would like to display my pages (dynamically in cms, grabbing > > >>>>>>>>> title), > > >>>>>>>>> in the application layout. > > >>>>>>>>> The yield is: In HAML > > >>>>>>>>> = yield :sidemenu > > > >>>>>>>>> The problem is that this yield is in the pages MVC. Is there a > > >>>>>>>>> way to > > >>>>>>>>> have a view instantiate another view? > > >>>>>>>>> Obviously the menu only shows when the url is mysite/pages/ > > >>>>>>>>> since > > >>>>>>>>> application.html.haml does not know about pages MVC. > > > >>>>>>>>> I hope this makes sense. > > > Rob Biedenharn http://agileconsultingllc.com > > R...-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Excellent article! Thanks for sharing. --Alan On Jan 29, 2008 1:37 PM, Sazima <rsazima-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Tresero, > > Didn''t have time to read thoroughly, but it seems this paper could > help a lot: > > > http://www.railsdev.ws/blog/wp-content/uploads/2007/10/modular_page_assembly_in_rails.pdf > > Cheers, Sazima > > On Jan 29, 4:57 pm, tresero <j...-xnFomyZ2uAo4Q++5jOxPmw@public.gmane.org> wrote: > > Yes, I believe so. I guess I have to put this in the controllers/ > > application.rb. > > I will look at it tonight and let you know. > > > > Thanks > > > > On Jan 29, 8:53 am, Rob Biedenharn <R...-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org> > > wrote: > > > > > On Jan 29, 2008, at 11:28 AM, tresero wrote: > > > > > > Rob, > > > > Thanks for the info, but this is not testing. > > > > Let me see if I can explain it another way with a different scenario > > > > (and I could be doing this completely wrong in my thinking). > > > > I have a site, one component is a blog, so there is a blog model, > > > > > ...So there''s a Blog.headlines that returns an array of headlines (or > > > Blog.headlines(n) to get the most recent n headlines) > > > > > > controller and view. I also have an application view which is the > main > > > > view on the whole site. > > > > If I wanted to get a random blog headline on the site, how would I > go > > > > about doing it? If I am not on a blog url, application does not know > > > > how to get at the data. > > > > > That controller calls Blog.random_headline (possibly in a > > > before_filter) and the layout incorporates the view for the headline. > > > > > > So I hope that makes more sense. I am thinking I need to do some > query > > > > in controllers/application.rb. I was hoping to make it DRY and not > > > > repeat the code from blog.rb. > > > > > > Thanks > > > > Jon > > > > > It that becoming clear? > > > -Rob > > > > > > On Jan 28, 10:12 pm, Rob Biedenharn <R...-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org> > > > > wrote: > > > >> I''m not sure I understand what you''re really trying to do, but let > me > > > >> throw this out to you: > > > > > >> In your views, avoid having "code". Use the instance variables set > > > >> by > > > >> the controller and try to do nothing more than simple tests and > loops > > > >> (@things.each or render :partial => ''...'', :collection => @things) > > > > > >> In your controllers, avoid the temptation to put too much code and > > > >> don''t (DON''T) put any SQL in the controller. If you find yourself > > > >> putting HTML into a controller method, you probably should be in > the > > > >> view or at least in a helper. > > > > > >> In your models, do the heavy lifting, but rest the weight on > > > >> ActiveRecord associations where you can. Whenever you want to put > > > >> a :conditions clause on a finder in a controller, go to the model > and > > > >> put a new method that does exactly what you need. > > > > > >> You were writing tests, right? Seriously, try to have a test for > > > >> every bit of your code that isn''t so trivial that it couldn''t > > > >> possibly > > > >> break. (Take careful note that the definitions of "trivial" and > > > >> "...couldn''t possibly..." will vary over time according to the > > > >> balance > > > >> between fear and experience -- pay attention to the feedback loop!) > > > > > >> -Rob > > > > > >> On Jan 29, 2008, at 12:50 AM, tresero wrote: > > > > > >>> I get that part, the problem is how to use a model in the "main" > > > >>> template. The sidebar does a query to pull all page titles and > > > >>> display > > > >>> them on the main template. > > > >>> The main template does not know how to deal with pages. Therefor > > > >>> the: > > > >>> - for item in @pages > > > >>> part fails, for obvious reasons. I need a way to get the pages > > > >>> model/ > > > >>> controller logic into the main template. > > > >>> Maybe there is no way, I can alway do raw sql, but I am trying to > do > > > >>> it the rails way ;) > > > > > >>> On Jan 28, 6:00 pm, Rob Biedenharn <R...-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org> > > > >>> wrote: > > > >>>> In your pages/show.rhtml > > > >>>> <% content_for :heading do -%> > > > >>>> <h1>Hey, I''m a Heading!</h1> > > > >>>> <% end -%> > > > > > >>>> <ul> > > > >>>> <li>I''m a list</li> > > > >>>> </ul > > > > > >>>> Then in application.rhtml (or whatever file you call out for the > > > >>>> layout): > > > > > >>>> <html> > > > >>>> <head><title>Example</title></head> > > > >>>> <body> > > > >>>> <%= yield :heading %> > > > >>>> <p>where''s the list</p> > > > >>>> <%= yield %> > > > >>>> </body> > > > >>>> </html> > > > > > >>>> Will generate: > > > > > >>>> <html> > > > >>>> <head><title>Example</title></head> > > > >>>> <body> > > > >>>> <h1>Hey, I''m a Heading!</h1> > > > >>>> <p>where''s the list</p> > > > > > >>>> <ul> > > > >>>> <li>I''m a list</li> > > > >>>> </ul > > > >>>> </body> > > > >>>> </html> > > > > > >>>> Is that what you''re trying to understand? > > > > > >>>> -Rob > > > > > >>>> On Jan 28, 2008, at 8:24 PM, tresero wrote: > > > > > >>>>> Let me phrase this another way, how can I use data from a > specific > > > >>>>> controller in an application view. I don''t see something like > > > >>>>> include > > > >>>>> pages which would gather the pages and pass them to the > > > >>>>> application.rhtml > > > > > >>>>> On Jan 28, 3:39 pm, tresero <j...-xnFomyZ2uAo4Q++5jOxPmw@public.gmane.org> wrote: > > > >>>>>> I tried this, but it does not use the pages controller, so it > > > >>>>>> errors > > > >>>>>> out. > > > >>>>>> Is there a way to include the pages controller in the main > > > >>>>>> application? > > > > > >>>>>> On Jan 28, 3:34 pm, tresero <j...-xnFomyZ2uAo4Q++5jOxPmw@public.gmane.org> wrote: > > > > > >>>>>>> It is not a partial, in the application view I am calling: > > > >>>>>>> = yield :sidemenu > > > > > >>>>>>> sidemenu is defined in pages/show.rhtml > > > > > >>>>>>> I can''t use a partial in a view can I? > > > > > >>>>>>> On Jan 28, 3:29 pm, Matt White <whit...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > >>>>>>>> Not exactly sure what you''re referring to when you say "in > the > > > >>>>>>>> pages > > > >>>>>>>> MVC". However, it sounds like you might be trying to render a > > > >>>>>>>> partial, > > > >>>>>>>> in the which case you would use: > > > > > >>>>>>>> render :partial => "filename.rhtml" > > > > > >>>>>>>> Is that what you''re trying to do? > > > > > >>>>>>>> On Jan 28, 3:44 pm, tresero <j...-xnFomyZ2uAo4Q++5jOxPmw@public.gmane.org> wrote: > > > > > >>>>>>>>> I am currently in a brain freeze. > > > >>>>>>>>> I would like to display my pages (dynamically in cms, > grabbing > > > >>>>>>>>> title), > > > >>>>>>>>> in the application layout. > > > >>>>>>>>> The yield is: In HAML > > > >>>>>>>>> = yield :sidemenu > > > > > >>>>>>>>> The problem is that this yield is in the pages MVC. Is there > a > > > >>>>>>>>> way to > > > >>>>>>>>> have a view instantiate another view? > > > >>>>>>>>> Obviously the menu only shows when the url is mysite/pages/ > > > >>>>>>>>> since > > > >>>>>>>>> application.html.haml does not know about pages MVC. > > > > > >>>>>>>>> I hope this makes sense. > > > > > Rob Biedenharn http://agileconsultingllc.com > > > R...-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
OK, I hate to open this backup but I am still stuck.
Let me explain again.
I have a template for the entire site, it is called
application.html.haml (I am using haml).
I have a controller called pages which is a mini-cms and is modeled
after vaporbase.
I want to have on the left side of my application layout the page
titles and children.
In my application.html.haml I have the following line:
= render(:partial => "pages/sidemenu.html.haml", :locals
=>{:pages
=> @pages} )
pages/sidemenu.html.haml is:
%h3 Pages
%ul{:id=>"leftmenu", :class=>"rMenu-wide rMenu-ver
rMenu"}
- for item in @pages
= link_to item.title, page_url(:id => item.name)
If I am in the url /pages/ everything renders correctly.
Outside of /pages/, I get the following error:
You have a nil object when you didn''t expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.each
This is related to not seeing an instance var named pages.
How can I use the data from pages site-wide? I know I am missing
something obvious.
Thanks
On Jan 29, 12:30 pm, "Alan Smith"
<alan0...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> Excellent article! Thanks for sharing.
>
> --Alan
>
> On Jan 29, 2008 1:37 PM, Sazima
<rsaz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>
>
>
> > Tresero,
>
> > Didn''t have time to read thoroughly, but it seems this paper
could
> > help a lot:
>
>
>http://www.railsdev.ws/blog/wp-content/uploads/2007/10/modular_page_a...
>
> > Cheers, Sazima
>
> > On Jan 29, 4:57 pm, tresero
<j...-xnFomyZ2uAo4Q++5jOxPmw@public.gmane.org> wrote:
> > > Yes, I believe so. I guess I have to put this in the controllers/
> > > application.rb.
> > > I will look at it tonight and let you know.
>
> > > Thanks
>
> > > On Jan 29, 8:53 am, Rob Biedenharn
<R...-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org>
> > > wrote:
>
> > > > On Jan 29, 2008, at 11:28 AM, tresero wrote:
>
> > > > > Rob,
> > > > > Thanks for the info, but this is not testing.
> > > > > Let me see if I can explain it another way with a
different scenario
> > > > > (and I could be doing this completely wrong in my
thinking).
> > > > > I have a site, one component is a blog, so there is a
blog model,
>
> > > > ...So there''s a Blog.headlines that returns an
array of headlines (or
> > > > Blog.headlines(n) to get the most recent n headlines)
>
> > > > > controller and view. I also have an application view
which is the
> > main
> > > > > view on the whole site.
> > > > > If I wanted to get a random blog headline on the site,
how would I
> > go
> > > > > about doing it? If I am not on a blog url, application
does not know
> > > > > how to get at the data.
>
> > > > That controller calls Blog.random_headline (possibly in a
> > > > before_filter) and the layout incorporates the view for the
headline.
>
> > > > > So I hope that makes more sense. I am thinking I need
to do some
> > query
> > > > > in controllers/application.rb. I was hoping to make it
DRY and not
> > > > > repeat the code from blog.rb.
>
> > > > > Thanks
> > > > > Jon
>
> > > > It that becoming clear?
> > > > -Rob
>
> > > > > On Jan 28, 10:12 pm, Rob Biedenharn
<R...-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org>
> > > > > wrote:
> > > > >> I''m not sure I understand what
you''re really trying to do, but let
> > me
> > > > >> throw this out to you:
>
> > > > >> In your views, avoid having "code". Use
the instance variables set
> > > > >> by
> > > > >> the controller and try to do nothing more than
simple tests and
> > loops
> > > > >> (@things.each or render :partial =>
''...'', :collection => @things)
>
> > > > >> In your controllers, avoid the temptation to put
too much code and
> > > > >> don''t (DON''T) put any SQL in the
controller. If you find yourself
> > > > >> putting HTML into a controller method, you probably
should be in
> > the
> > > > >> view or at least in a helper.
>
> > > > >> In your models, do the heavy lifting, but rest the
weight on
> > > > >> ActiveRecord associations where you can. Whenever
you want to put
> > > > >> a :conditions clause on a finder in a controller,
go to the model
> > and
> > > > >> put a new method that does exactly what you need.
>
> > > > >> You were writing tests, right? Seriously, try to
have a test for
> > > > >> every bit of your code that isn''t so
trivial that it couldn''t
> > > > >> possibly
> > > > >> break. (Take careful note that the definitions of
"trivial" and
> > > > >> "...couldn''t possibly..." will
vary over time according to the
> > > > >> balance
> > > > >> between fear and experience -- pay attention to the
feedback loop!)
>
> > > > >> -Rob
>
> > > > >> On Jan 29, 2008, at 12:50 AM, tresero wrote:
>
> > > > >>> I get that part, the problem is how to use a
model in the "main"
> > > > >>> template. The sidebar does a query to pull all
page titles and
> > > > >>> display
> > > > >>> them on the main template.
> > > > >>> The main template does not know how to deal
with pages. Therefor
> > > > >>> the:
> > > > >>> - for item in @pages
> > > > >>> part fails, for obvious reasons. I need a way
to get the pages
> > > > >>> model/
> > > > >>> controller logic into the main template.
> > > > >>> Maybe there is no way, I can alway do raw sql,
but I am trying to
> > do
> > > > >>> it the rails way ;)
>
> > > > >>> On Jan 28, 6:00 pm, Rob Biedenharn
<R...-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org>
> > > > >>> wrote:
> > > > >>>> In your pages/show.rhtml
> > > > >>>> <% content_for :heading do -%>
> > > > >>>> <h1>Hey, I''m a
Heading!</h1>
> > > > >>>> <% end -%>
>
> > > > >>>> <ul>
> > > > >>>> <li>I''m a list</li>
> > > > >>>> </ul
>
> > > > >>>> Then in application.rhtml (or whatever file
you call out for the
> > > > >>>> layout):
>
> > > > >>>> <html>
> > > > >>>>
<head><title>Example</title></head>
> > > > >>>> <body>
> > > > >>>> <%= yield :heading %>
> > > > >>>> <p>where''s the
list</p>
> > > > >>>> <%= yield %>
> > > > >>>> </body>
> > > > >>>> </html>
>
> > > > >>>> Will generate:
>
> > > > >>>> <html>
> > > > >>>>
<head><title>Example</title></head>
> > > > >>>> <body>
> > > > >>>> <h1>Hey, I''m a
Heading!</h1>
> > > > >>>> <p>where''s the
list</p>
>
> > > > >>>> <ul>
> > > > >>>> <li>I''m a list</li>
> > > > >>>> </ul
> > > > >>>> </body>
> > > > >>>> </html>
>
> > > > >>>> Is that what you''re trying to
understand?
>
> > > > >>>> -Rob
>
> > > > >>>> On Jan 28, 2008, at 8:24 PM, tresero wrote:
>
> > > > >>>>> Let me phrase this another way, how can
I use data from a
> > specific
> > > > >>>>> controller in an application view. I
don''t see something like
> > > > >>>>> include
> > > > >>>>> pages which would gather the pages and
pass them to the
> > > > >>>>> application.rhtml
>
> > > > >>>>> On Jan 28, 3:39 pm, tresero
<j...-xnFomyZ2uAo4Q++5jOxPmw@public.gmane.org> wrote:
> > > > >>>>>> I tried this, but it does not use
the pages controller, so it
> > > > >>>>>> errors
> > > > >>>>>> out.
> > > > >>>>>> Is there a way to include the pages
controller in the main
> > > > >>>>>> application?
>
> > > > >>>>>> On Jan 28, 3:34 pm, tresero
<j...-xnFomyZ2uAo4Q++5jOxPmw@public.gmane.org> wrote:
>
> > > > >>>>>>> It is not a partial, in the
application view I am calling:
> > > > >>>>>>> = yield :sidemenu
>
> > > > >>>>>>> sidemenu is defined in
pages/show.rhtml
>
> > > > >>>>>>> I can''t use a partial
in a view can I?
>
> > > > >>>>>>> On Jan 28, 3:29 pm, Matt White
<whit...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>
> > > > >>>>>>>> Not exactly sure what
you''re referring to when you say "in
> > the
> > > > >>>>>>>> pages
> > > > >>>>>>>> MVC". However, it
sounds like you might be trying to render a
> > > > >>>>>>>> partial,
> > > > >>>>>>>> in the which case you would
use:
>
> > > > >>>>>>>> render :partial =>
"filename.rhtml"
>
> > > > >>>>>>>> Is that what
you''re trying to do?
>
> > > > >>>>>>>> On Jan 28, 3:44 pm, tresero
<j...-xnFomyZ2uAo4Q++5jOxPmw@public.gmane.org> wrote:
>
> > > > >>>>>>>>> I am currently in a
brain freeze.
> > > > >>>>>>>>> I would like to display
my pages (dynamically in cms,
> > grabbing
> > > > >>>>>>>>> title),
> > > > >>>>>>>>> in the application
layout.
> > > > >>>>>>>>> The yield is: In HAML
> > > > >>>>>>>>> = yield :sidemenu
>
> > > > >>>>>>>>> The problem is that
this yield is in the pages MVC. Is there
> > a
> > > > >>>>>>>>> way to
> > > > >>>>>>>>> have a view instantiate
another view?
> > > > >>>>>>>>> Obviously the menu only
shows when the url is mysite/pages/
> > > > >>>>>>>>> since
> > > > >>>>>>>>> application.html.haml
does not know about pages MVC.
>
> > > > >>>>>>>>> I hope this makes
sense.
>
> > > > Rob Biedenharn http://agileconsultingllc.com
> > > > R...-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
OK, I hate to open this backup but I am still stuck.
Let me explain again.
I have a template for the entire site, it is called
application.html.haml (I am using haml).
I have a controller called pages which is a mini-cms and is modeled
after vaporbase.
I want to have on the left side of my application layout the page
titles and children.
In my application.html.haml I have the following line:
= render(:partial => "pages/sidemenu.html.haml", :locals
=>{:pages
=> @pages} )
pages/sidemenu.html.haml is:
%h3 Pages
%ul{:id=>"leftmenu", :class=>"rMenu-wide rMenu-ver
rMenu"}
- for item in @pages
= link_to item.title, page_url(:id => item.name)
If I am in the url /pages/ everything renders correctly.
Outside of /pages/, I get the following error:
You have a nil object when you didn''t expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.each
This is related to not seeing an instance var named pages.
How can I use the data from pages site-wide? I know I am missing
something obvious.
Thanks
On Jan 29, 12:30 pm, "Alan Smith"
<alan0...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> Excellent article! Thanks for sharing.
>
> --Alan
>
> On Jan 29, 2008 1:37 PM, Sazima
<rsaz...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>
>
>
> > Tresero,
>
> > Didn''t have time to read thoroughly, but it seems this paper
could
> > help a lot:
>
>
>http://www.railsdev.ws/blog/wp-content/uploads/2007/10/modular_page_a...
>
> > Cheers, Sazima
>
> > On Jan 29, 4:57 pm, tresero
<j...-xnFomyZ2uAo4Q++5jOxPmw@public.gmane.org> wrote:
> > > Yes, I believe so. I guess I have to put this in the controllers/
> > > application.rb.
> > > I will look at it tonight and let you know.
>
> > > Thanks
>
> > > On Jan 29, 8:53 am, Rob Biedenharn
<R...-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org>
> > > wrote:
>
> > > > On Jan 29, 2008, at 11:28 AM, tresero wrote:
>
> > > > > Rob,
> > > > > Thanks for the info, but this is not testing.
> > > > > Let me see if I can explain it another way with a
different scenario
> > > > > (and I could be doing this completely wrong in my
thinking).
> > > > > I have a site, one component is a blog, so there is a
blog model,
>
> > > > ...So there''s a Blog.headlines that returns an
array of headlines (or
> > > > Blog.headlines(n) to get the most recent n headlines)
>
> > > > > controller and view. I also have an application view
which is the
> > main
> > > > > view on the whole site.
> > > > > If I wanted to get a random blog headline on the site,
how would I
> > go
> > > > > about doing it? If I am not on a blog url, application
does not know
> > > > > how to get at the data.
>
> > > > That controller calls Blog.random_headline (possibly in a
> > > > before_filter) and the layout incorporates the view for the
headline.
>
> > > > > So I hope that makes more sense. I am thinking I need
to do some
> > query
> > > > > in controllers/application.rb. I was hoping to make it
DRY and not
> > > > > repeat the code from blog.rb.
>
> > > > > Thanks
> > > > > Jon
>
> > > > It that becoming clear?
> > > > -Rob
>
> > > > > On Jan 28, 10:12 pm, Rob Biedenharn
<R...-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org>
> > > > > wrote:
> > > > >> I''m not sure I understand what
you''re really trying to do, but let
> > me
> > > > >> throw this out to you:
>
> > > > >> In your views, avoid having "code". Use
the instance variables set
> > > > >> by
> > > > >> the controller and try to do nothing more than
simple tests and
> > loops
> > > > >> (@things.each or render :partial =>
''...'', :collection => @things)
>
> > > > >> In your controllers, avoid the temptation to put
too much code and
> > > > >> don''t (DON''T) put any SQL in the
controller. If you find yourself
> > > > >> putting HTML into a controller method, you probably
should be in
> > the
> > > > >> view or at least in a helper.
>
> > > > >> In your models, do the heavy lifting, but rest the
weight on
> > > > >> ActiveRecord associations where you can. Whenever
you want to put
> > > > >> a :conditions clause on a finder in a controller,
go to the model
> > and
> > > > >> put a new method that does exactly what you need.
>
> > > > >> You were writing tests, right? Seriously, try to
have a test for
> > > > >> every bit of your code that isn''t so
trivial that it couldn''t
> > > > >> possibly
> > > > >> break. (Take careful note that the definitions of
"trivial" and
> > > > >> "...couldn''t possibly..." will
vary over time according to the
> > > > >> balance
> > > > >> between fear and experience -- pay attention to the
feedback loop!)
>
> > > > >> -Rob
>
> > > > >> On Jan 29, 2008, at 12:50 AM, tresero wrote:
>
> > > > >>> I get that part, the problem is how to use a
model in the "main"
> > > > >>> template. The sidebar does a query to pull all
page titles and
> > > > >>> display
> > > > >>> them on the main template.
> > > > >>> The main template does not know how to deal
with pages. Therefor
> > > > >>> the:
> > > > >>> - for item in @pages
> > > > >>> part fails, for obvious reasons. I need a way
to get the pages
> > > > >>> model/
> > > > >>> controller logic into the main template.
> > > > >>> Maybe there is no way, I can alway do raw sql,
but I am trying to
> > do
> > > > >>> it the rails way ;)
>
> > > > >>> On Jan 28, 6:00 pm, Rob Biedenharn
<R...-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org>
> > > > >>> wrote:
> > > > >>>> In your pages/show.rhtml
> > > > >>>> <% content_for :heading do -%>
> > > > >>>> <h1>Hey, I''m a
Heading!</h1>
> > > > >>>> <% end -%>
>
> > > > >>>> <ul>
> > > > >>>> <li>I''m a list</li>
> > > > >>>> </ul
>
> > > > >>>> Then in application.rhtml (or whatever file
you call out for the
> > > > >>>> layout):
>
> > > > >>>> <html>
> > > > >>>>
<head><title>Example</title></head>
> > > > >>>> <body>
> > > > >>>> <%= yield :heading %>
> > > > >>>> <p>where''s the
list</p>
> > > > >>>> <%= yield %>
> > > > >>>> </body>
> > > > >>>> </html>
>
> > > > >>>> Will generate:
>
> > > > >>>> <html>
> > > > >>>>
<head><title>Example</title></head>
> > > > >>>> <body>
> > > > >>>> <h1>Hey, I''m a
Heading!</h1>
> > > > >>>> <p>where''s the
list</p>
>
> > > > >>>> <ul>
> > > > >>>> <li>I''m a list</li>
> > > > >>>> </ul
> > > > >>>> </body>
> > > > >>>> </html>
>
> > > > >>>> Is that what you''re trying to
understand?
>
> > > > >>>> -Rob
>
> > > > >>>> On Jan 28, 2008, at 8:24 PM, tresero wrote:
>
> > > > >>>>> Let me phrase this another way, how can
I use data from a
> > specific
> > > > >>>>> controller in an application view. I
don''t see something like
> > > > >>>>> include
> > > > >>>>> pages which would gather the pages and
pass them to the
> > > > >>>>> application.rhtml
>
> > > > >>>>> On Jan 28, 3:39 pm, tresero
<j...-xnFomyZ2uAo4Q++5jOxPmw@public.gmane.org> wrote:
> > > > >>>>>> I tried this, but it does not use
the pages controller, so it
> > > > >>>>>> errors
> > > > >>>>>> out.
> > > > >>>>>> Is there a way to include the pages
controller in the main
> > > > >>>>>> application?
>
> > > > >>>>>> On Jan 28, 3:34 pm, tresero
<j...-xnFomyZ2uAo4Q++5jOxPmw@public.gmane.org> wrote:
>
> > > > >>>>>>> It is not a partial, in the
application view I am calling:
> > > > >>>>>>> = yield :sidemenu
>
> > > > >>>>>>> sidemenu is defined in
pages/show.rhtml
>
> > > > >>>>>>> I can''t use a partial
in a view can I?
>
> > > > >>>>>>> On Jan 28, 3:29 pm, Matt White
<whit...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>
> > > > >>>>>>>> Not exactly sure what
you''re referring to when you say "in
> > the
> > > > >>>>>>>> pages
> > > > >>>>>>>> MVC". However, it
sounds like you might be trying to render a
> > > > >>>>>>>> partial,
> > > > >>>>>>>> in the which case you would
use:
>
> > > > >>>>>>>> render :partial =>
"filename.rhtml"
>
> > > > >>>>>>>> Is that what
you''re trying to do?
>
> > > > >>>>>>>> On Jan 28, 3:44 pm, tresero
<j...-xnFomyZ2uAo4Q++5jOxPmw@public.gmane.org> wrote:
>
> > > > >>>>>>>>> I am currently in a
brain freeze.
> > > > >>>>>>>>> I would like to display
my pages (dynamically in cms,
> > grabbing
> > > > >>>>>>>>> title),
> > > > >>>>>>>>> in the application
layout.
> > > > >>>>>>>>> The yield is: In HAML
> > > > >>>>>>>>> = yield :sidemenu
>
> > > > >>>>>>>>> The problem is that
this yield is in the pages MVC. Is there
> > a
> > > > >>>>>>>>> way to
> > > > >>>>>>>>> have a view instantiate
another view?
> > > > >>>>>>>>> Obviously the menu only
shows when the url is mysite/pages/
> > > > >>>>>>>>> since
> > > > >>>>>>>>> application.html.haml
does not know about pages MVC.
>
> > > > >>>>>>>>> I hope this makes
sense.
>
> > > > Rob Biedenharn http://agileconsultingllc.com
> > > > R...-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---