Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8805015
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T01:45:19+00:00 2026-06-14T01:45:19+00:00

Every show action in my app has the same template for every model (it

  • 0

Every show action in my app has the same template for every model (it is an Admin-portal type interface). I have a view show.html.erb that all of these models inherit.

The controllers all use InheritedResources, so I have access to some helper variables such as resource, which I use to display the attributes for the model being shown through resource.attributes in my parent view.

What I would like to be able to do is whitelist which attributes are being shown in each model. I have thought of two ways to do this… the first is to define some method in a class my model’s inherit from, say it is called attr_visible and define each attribute in the model. The reason I don’t like this approach is that it puts too much of the view logic in the models. I would rather provide my views with the model, and let the view determine what is displayed.

The second approach is what this question is about. I want to have a file /app/views/users/show.html.erb, and set which attributes for a User I would like to be shown, say something like:

@attributes = [:name, :email, :etc]

And then pass them to the parent view which I described in the beginning of this question. That view would then be able to loop through @attributes and display the attributes necessary.

Is it possible to use a “super“-type method from views? Everything I have read about view inheritance suggests the view is loaded based on where it is located in the directory structure, and then after that you’re out of luck.

edit: I have sort of done what I want. I defined a partial _show.html.erb in the /app/views/users directory that looks like:

<% @attributes = ['name', ...] %>

And then in the parent view I call <%= render "show" %> before looping through @attributes. This works, but feels clunky since I am not actually rendering anything when I call render. Is there a better way?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T01:45:21+00:00Added an answer on June 14, 2026 at 1:45 am

    You can use a presenter for this. Adding “view” logic to a model is better done through this type of object. Take a look at draper.

    Once the resource is decorated, you can just call visible_attributes or whatever. Of course, you would need to implement that method for each resource.

    Views inheritance works when looking for a view, not when rendering it. Take a look at the original plugin implementation.

    Other way would be to make the show parent view to call render on resource and create several partials for the classes.

    For a better understanding on Rails Views, I recommend The Rails View: Create a Beautiful and Maintainable User Experience

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a book app. User choose a book and UITextView show it. Every
in my app i have an UITableView with 120 rows and every row has
I have a page with many tooltips. I want to show/hide every one seperatly
We can't do read someValue :: someDataType or show someValue for every type because
Every second line is coloured on the table in the view. I have the
I have a navigation app that has many screens the user navigates to. A
i have a flex action script web app, i which i am adding a
I have this in courses.html.erb under app/views/students <% if @student.courses.count < Course.count then%> <%
My iPad (!!) app has a table view as the UISplitViewControllers details controller. To
I have a Store model. And two controllers: stores_controller admin/stores_controller now in the list

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.