Yielding scaffold in another view best practice.

18 views
Skip to first unread message

Deepak Sharma

unread,
Oct 25, 2015, 8:59:58 AM10/25/15
to rubyonra...@googlegroups.com
In my app I have dashboard part where all major function will perform,
besides that I have few scaffolds (question, performance etc) which I
want to display in that dashboard. I'm little confused what will the
best practice of doing this.

1) Make partial and then render that partial
2) By using content_for and then yield it

It sounds silly but I have little confusing in above two points too.

If I choose first option then how do I move from one scaffold to
another (dashboard UI / content remain unchanged only scaffold part
will effect)

I did experiment with second only but it works only in
application.html.erb instead of any other view.

Please guide me what should I do to re-factor my problem instead of
writing same code again and again.

--
Cheers!

Deepak Kumar Sharma
Guru Nanak Dev Engineering College
India!

Blog: http://deekysharma.wordpress.com

Colin Law

unread,
Oct 25, 2015, 9:42:05 AM10/25/15
to Ruby on Rails: Talk
On 25 October 2015 at 12:59, Deepak Sharma <deeky....@gmail.com> wrote:
> In my app I have dashboard part where all major function will perform,
> besides that I have few scaffolds (question, performance etc) which I
> want to display in that dashboard. I'm little confused what will the
> best practice of doing this.
>
> 1) Make partial and then render that partial
> 2) By using content_for and then yield it
>
> It sounds silly but I have little confusing in above two points too.
>
> If I choose first option then how do I move from one scaffold to
> another (dashboard UI / content remain unchanged only scaffold part
> will effect)


The usual way to do this would be by rendering partials. You can
render different partials dependent on the context. Alternatively,
instead of rendering the scaffolds as partials from the dashboard,
render the dashboard as partials from the scaffold. Often this is the
simpler approach.

Colin

Deepak Sharma

unread,
Oct 25, 2015, 11:00:33 AM10/25/15
to rubyonra...@googlegroups.com
On Sun, Oct 25, 2015 at 7:10 PM, Colin Law <cla...@gmail.com> wrote:
> The usual way to do this would be by rendering partials. You can
> render different partials dependent on the context. Alternatively,
> instead of rendering the scaffolds as partials from the dashboard,
> render the dashboard as partials from the scaffold. Often this is the
> simpler approach.

Rendering dashboard partial sounds good. But I leads to huge amount of
CSS code and hard coding.

Colin Law

unread,
Oct 25, 2015, 11:23:47 AM10/25/15
to Ruby on Rails: Talk
On 25 October 2015 at 14:59, Deepak Sharma <deeky....@gmail.com> wrote:
> On Sun, Oct 25, 2015 at 7:10 PM, Colin Law <cla...@gmail.com> wrote:
>> The usual way to do this would be by rendering partials. You can
>> render different partials dependent on the context. Alternatively,
>> instead of rendering the scaffolds as partials from the dashboard,
>> render the dashboard as partials from the scaffold. Often this is the
>> simpler approach.
>
> Rendering dashboard partial sounds good. But I leads to huge amount of
> CSS code and hard coding.

Why is it any different to your original idea?

Colin

Colin Law

unread,
Oct 25, 2015, 11:32:02 AM10/25/15
to Ruby on Rails: Talk
On 25 October 2015 at 14:59, Deepak Sharma <deeky....@gmail.com> wrote:
> On Sun, Oct 25, 2015 at 7:10 PM, Colin Law <cla...@gmail.com> wrote:
>> The usual way to do this would be by rendering partials. You can
>> render different partials dependent on the context. Alternatively,
>> instead of rendering the scaffolds as partials from the dashboard,
>> render the dashboard as partials from the scaffold. Often this is the
>> simpler approach.
>
> Rendering dashboard partial sounds good. But I leads to huge amount of
> CSS code and hard coding.

In fact I didn't write what I meant to write. Put the rendering of
the dashboard partials in layouts/application.html.erb (or another
layout used by relevant views if not everything needs the dashboard)
and yield from there for the contents.

Colin

Deepak Sharma

unread,
Oct 25, 2015, 12:54:31 PM10/25/15
to rubyonra...@googlegroups.com
On Sun, Oct 25, 2015 at 9:01 PM, Colin Law <cla...@gmail.com> wrote:
> In fact I didn't write what I meant to write. Put the rendering of
> the dashboard partials in layouts/application.html.erb (or another
> layout used by relevant views if not everything needs the dashboard)
> and yield from there for the contents.

This is what my dashboard looks like : http://awesomescreenshot.com/0925cm5j66
Now I want to render my scaffolds in that white portion. Dashboard
partial seems good to me :).
Reply all
Reply to author
Forward
0 new messages