开发者

Best practice for composite application

I am new to rails and I would like to know which is the best practice for creating composite views.

I have a show view for my model, let's say it is called Project. In my project show view, I have to show a list of Characters.

Characters and Project are not really related to each other but it is a requirement to show them on the same page.

开发者_Python百科

I could do something like this:

def show
  @project = Project.first
  @characters = Character.all
end

And have a partial for listing my characters. Is this the best way?


That's fine. It looks simple enough for your use case.

If you get to the point where multiple views have at least three instance variable assignments and multiple partials in each page, it stops being simple and you might like to look for an alternative. You might like to look for an alternative anyway, just for fun.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜