Dan Brooking
2012-Dec-08 15:39 UTC
Calling multiple ERB files for different models from single ERB?
I imagine this is a pretty common thing so I''m assuming there is a "rails" way to do this. I have an index page for my app and when a user logs in, I am querying various models to get lists of the objects associated with a user. I want to display this stuff on the main page of the app, kind of like a dashboard. So... basically, is there an easy way to call the index.html.erb associated with one model from within another? I''ve got the list of objects I''d want rendered. How would I pass that in? From my searches, it seems like I can create an ERB object, bind the var to that ERB object, and then render it. But was just wondering if that was the right way? 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/bhU5hCGR8DsJ. For more options, visit https://groups.google.com/groups/opt_out.
Walter Lee Davis
2012-Dec-08 15:45 UTC
Re: Calling multiple ERB files for different models from single ERB?
On Dec 8, 2012, at 10:39 AM, Dan Brooking wrote:> I imagine this is a pretty common thing so I''m assuming there is a "rails" way to do this. > > I have an index page for my app and when a user logs in, I am querying various models to get lists of the objects associated with a user. I want to display this stuff on the main page of the app, kind of like a dashboard. > > So... basically, is there an easy way to call the index.html.erb associated with one model from within another? I''ve got the list of objects I''d want rendered. How would I pass that in? From my searches, it seems like I can create an ERB object, bind the var to that ERB object, and then render it. But was just wondering if that was the right way? > > ThanksHave you read the Rails Guide on Views yet? There''s a whole section on "partials" that I think would answer this for you neatly. If you''ve got multiple objects or collections already marshaled in your controller, you can pass them to the render call and specify a view partial (or let the conventions choose it for you) with something as simple as <%= render @my_collection %> or <%= render :partial => ''foos/bar'', :object => @baz %> Walter -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Dan Brooking
2012-Dec-08 15:48 UTC
Re: Calling multiple ERB files for different models from single ERB?
No I haven''t... I''ll give that a look. I''m really diving head first into this reading things as I encounter issues. I''ll give it a read. Thanks!! On Sat, Dec 8, 2012 at 10:45 AM, Walter Lee Davis <waltd-HQgmohHLjDZWk0Htik3J/w@public.gmane.org>wrote:> > On Dec 8, 2012, at 10:39 AM, Dan Brooking wrote: > > > I imagine this is a pretty common thing so I''m assuming there is a > "rails" way to do this. > > > > I have an index page for my app and when a user logs in, I am querying > various models to get lists of the objects associated with a user. I want > to display this stuff on the main page of the app, kind of like a dashboard. > > > > So... basically, is there an easy way to call the index.html.erb > associated with one model from within another? I''ve got the list of > objects I''d want rendered. How would I pass that in? From my searches, it > seems like I can create an ERB object, bind the var to that ERB object, and > then render it. But was just wondering if that was the right way? > > > > Thanks > > Have you read the Rails Guide on Views yet? There''s a whole section on > "partials" that I think would answer this for you neatly. If you''ve got > multiple objects or collections already marshaled in your controller, you > can pass them to the render call and specify a view partial (or let the > conventions choose it for you) with something as simple as <%= render > @my_collection %> or <%= render :partial => ''foos/bar'', :object => @baz %> > > Walter > > > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit https://groups.google.com/groups/opt_out. > > >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
Colin Law
2012-Dec-08 16:27 UTC
Re: Calling multiple ERB files for different models from single ERB?
On 8 December 2012 15:48, Dan Brooking <dmbrooking-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> No I haven''t... I''ll give that a look. I''m really diving head first into > this reading things as I encounter issues. > > I''ll give it a read. Thanks!!Also work right through a good tutorial such as railstutorial.org (which is free to use online) so that you understand the basics of Rails. Colin> > > On Sat, Dec 8, 2012 at 10:45 AM, Walter Lee Davis <waltd-HQgmohHLjDZWk0Htik3J/w@public.gmane.org> > wrote: >> >> >> On Dec 8, 2012, at 10:39 AM, Dan Brooking wrote: >> >> > I imagine this is a pretty common thing so I''m assuming there is a >> > "rails" way to do this. >> > >> > I have an index page for my app and when a user logs in, I am querying >> > various models to get lists of the objects associated with a user. I want to >> > display this stuff on the main page of the app, kind of like a dashboard. >> > >> > So... basically, is there an easy way to call the index.html.erb >> > associated with one model from within another? I''ve got the list of objects >> > I''d want rendered. How would I pass that in? From my searches, it seems like >> > I can create an ERB object, bind the var to that ERB object, and then render >> > it. But was just wondering if that was the right way? >> > >> > Thanks >> >> Have you read the Rails Guide on Views yet? There''s a whole section on >> "partials" that I think would answer this for you neatly. If you''ve got >> multiple objects or collections already marshaled in your controller, you >> can pass them to the render call and specify a view partial (or let the >> conventions choose it for you) with something as simple as <%= render >> @my_collection %> or <%= render :partial => ''foos/bar'', :object => @baz %> >> >> Walter >> >> >> >> -- >> 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> To unsubscribe from this group, send email to >> rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> For more options, visit https://groups.google.com/groups/opt_out. >> >> > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit https://groups.google.com/groups/opt_out. > >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
Dan Brooking
2012-Dec-08 16:55 UTC
Re: Calling multiple ERB files for different models from single ERB?
This is what I love about Rails/Ruby. There is so much ease to do so many things that when things start to look convoluted/hack-ish, it usually indicated bad design. In reading through the raisl guide and the rails tutorial, I''m seeing just how poor some of my prior design decisions are (and they appeared great at the time). On Sat, Dec 8, 2012 at 11:27 AM, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 8 December 2012 15:48, Dan Brooking <dmbrooking-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > No I haven''t... I''ll give that a look. I''m really diving head first into > > this reading things as I encounter issues. > > > > I''ll give it a read. Thanks!! > > Also work right through a good tutorial such as railstutorial.org > (which is free to use online) so that you understand the basics of > Rails. > > Colin > > > > > > > On Sat, Dec 8, 2012 at 10:45 AM, Walter Lee Davis <waltd-HQgmohHLjDZWk0Htik3J/w@public.gmane.org> > > wrote: > >> > >> > >> On Dec 8, 2012, at 10:39 AM, Dan Brooking wrote: > >> > >> > I imagine this is a pretty common thing so I''m assuming there is a > >> > "rails" way to do this. > >> > > >> > I have an index page for my app and when a user logs in, I am querying > >> > various models to get lists of the objects associated with a user. I > want to > >> > display this stuff on the main page of the app, kind of like a > dashboard. > >> > > >> > So... basically, is there an easy way to call the index.html.erb > >> > associated with one model from within another? I''ve got the list of > objects > >> > I''d want rendered. How would I pass that in? From my searches, it > seems like > >> > I can create an ERB object, bind the var to that ERB object, and then > render > >> > it. But was just wondering if that was the right way? > >> > > >> > Thanks > >> > >> Have you read the Rails Guide on Views yet? There''s a whole section on > >> "partials" that I think would answer this for you neatly. If you''ve got > >> multiple objects or collections already marshaled in your controller, > you > >> can pass them to the render call and specify a view partial (or let the > >> conventions choose it for you) with something as simple as <%= render > >> @my_collection %> or <%= render :partial => ''foos/bar'', :object => @baz > %> > >> > >> Walter > >> > >> > >> > >> -- > >> 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > >> To unsubscribe from this group, send email to > >> rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > >> For more options, visit https://groups.google.com/groups/opt_out. > >> > >> > > > > -- > > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > For more options, visit https://groups.google.com/groups/opt_out. > > > > > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit https://groups.google.com/groups/opt_out. > > >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.