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 6391855
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:44:23+00:00 2026-05-25T03:44:23+00:00

For people that only want the question, here it is : Is there a

  • 0

For people that only want the question, here it is :

Is there a way to specify the folder to look in when you call render on an object? I don’t want to specify the view, only the folder to look in.

And for people that want context :

I am working on an activity stream system (something that looks like google+/facebook).

I have “Activities”, which are exactly like google+ feeds (or facebook, or whatever!). So, I have a simple loop that display each activities, which are bound to one of the following object (polymorphic) : User, Group, Comment, Note.

In my view that render an activity (views/activities/_activity.html.erb), I have

<%= render activity.object %>

where activity.object is a reference to the bound object (User, Group, Note, Comment). If it’s a user, it goes to views/users/_user.html.erb and renders it. For a group, views/groups/_group.html.erb.

That works just fine. However, I come to the point where the rendering of a group in my activities should not be the same rendering as in the group list page. Is there a way to specify the folder to look in when you call render on an object? So that my :

<%= render activity.object %>

would become :

<%= render activity.object, :folder => 'views/activities/' %>

Note that I don’t want to specify which view directly, as I don’t want to do a case for each of the possible types of objects (User, Group, Note, Comment) in the activity. I want to to have the same behaviour as of right now, which means if it finds a views/activities/_user.html.erb, it would load any user in the activities with that view instead of the one in the views/users/_user.html.erb.

Thanks

  • 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-05-25T03:44:24+00:00Added an answer on May 25, 2026 at 3:44 am

    I’m not aware of any folder type option, but when I do this I usually do:

    <%= render "activities/#{activity.object.class.name.underscore}" %>
    

    That would give you similar behaviour.

    EDIT A good point below by Dominic, if your classes are nested in namespaces, you will have to include the appropriate structure.

    i.e.

     module Foo
       class Bar < ActiveRecord::Base
       end
     end
    
     # class.name is Foo::Bar, underscored is 'foo/bar'
    
     <%= render "activities/#{activity.object_type.underscore}" %>
     # will be in
     activities/foo/_bar.html
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I re-asked this question here because the people at ServerFault deemed that this is
I typically work on small-sized projects that involve only 2-3 people working on the
I'm developing application that can be useful only in my country(Ukraine). In Ukraine people
I have a PersonEditorModel that contains a list of people that I want represented
I often hear around here from test driven development people that having a function
I've been trying to find the answer to this question here. Several people seem
I've asked this question here , but I don't think I got my point
I know this question seems hacky and weird, but is there a way to
For those people that use NHibernate and similar stuff, why do you use it?
So I know of a few people that actually write their algorithms out in

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.