Forum: Ruby on Rails Are views inheritable

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
F59329dc91cba06600ff65c85fd3e93c?d=identicon&s=25 Anthony Green (acgreen)
on 2006-03-06 14:13
Is it possible to use a child model's controller to impliment it's
parents view before adding its own output ?

possibly by the use of super ?

_tony
6578456ff00ab3520b1fe684bc572b45?d=identicon&s=25 Łukasz Piestrzeniewicz (Guest)
on 2006-03-06 14:51
(Received via mailing list)
On 06/03/06, Anthony Green <email@acgreen.co.uk> wrote:
> Is it possible to use a child model's controller to impliment it's
> parents view before adding its own output ?
> possibly by the use of super ?

Use partials, for example:

File _common.rhtml

<h3>Common parts</h3>

File parent.rhtml

<%= render :partial => 'common' %>

File child.rhtml

<%= render :partial => 'common' %>
<p>Let's add some new contents</p>
F59329dc91cba06600ff65c85fd3e93c?d=identicon&s=25 Anthony Green (acgreen)
on 2006-03-06 15:55
> Use partials, for example:
>
> File _common.rhtml
>
> <h3>Common parts</h3>
>
> File parent.rhtml
>
> <%= render :partial => 'common' %>
>
> File child.rhtml
>
> <%= render :partial => 'common' %>
> <p>Let's add some new contents</p>

Doesn't the partial have to be in the model named directory for that to
work ?
ie
views/child/_common.rhtml

whereas I want it to use

views/parent/_common.rhtml

_tony
F59329dc91cba06600ff65c85fd3e93c?d=identicon&s=25 Anthony Green (acgreen)
on 2006-03-06 16:09
> views/parent/_common.rhtml
>
> _tony

 <%= render_partial 'parent/common', @user %>

_T
6578456ff00ab3520b1fe684bc572b45?d=identicon&s=25 Łukasz Piestrzeniewicz (Guest)
on 2006-03-06 16:16
(Received via mailing list)
Hi Anthony,

On 06/03/06, Anthony Green <email@acgreen.co.uk> wrote:
> Doesn't the partial have to be in the model named directory for that to
> work ?
> ie
> views/child/_common.rhtml
>
> whereas I want it to use
>
> views/parent/_common.rhtml

It may be anywhere, you just have to provide a proper path:

app/views/
 - parent/
  - _common.rhtml
  - list.rhtml (uses :partial => 'common' - local path)
 - child/
  - list.rhtml (uses :partial => '/parent/common' - path from other
controller)
This topic is locked and can not be replied to.