简体   繁体   中英

Ruby on Rails: partial view inheritance

I want to get next thing...

    # For ArticlesController > ApplicationController
    # in view
    render 'articles/edit/form'
    # tries 'app/views/articles/edit/_form.html.erb'
    # then tries 'app/views/articles/_form.html.erb'
    # then what it wants

Or maybe render with array partial option:

    # For ArticlesController > ApplicationController
    # in view
    render_exists ['articles/edit/form', 'articles/new/form']
    # tries 'app/views/articles/edit/_form.html.erb'
    # then tries 'app/views/articles/new/_form.html.erb'
    # then what it wants

This isn't realized, is this? But maybe some gems for 3.2 or monkeypatches... And don't you know pull requests to rails about it? Thanks!

UPD That's isn't controller-based view inheritance. This should work for (at the same page):

    render `articles/edit/form`
    render `comments/edit/form`

That already exists, and it's very similar to the controller inheritance.

You must follow a conventional strategy, however. You would put your global partial in app/views/application , then you can put a more specific one at each inherited level, like app/views/articles .

Take a look at the following railscast for more details: #269 Template Inheritance

I'm using the mechanism I described in an article in the rails forum

It works a treat for me though I hear there is now some built in support in the latest versions or at least effort is under way to do add such a feature.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM