Layout, application_helper and partial ! Help !

You can include the path to your partial when you render it:

render :partial => ‘user/my_partial1’
render :partial => ‘comment/my_partial2’

As for the way you’ve describe your app, it sounds like you’re triggering a lot of queries from your helpers. Personaly I like to keep that to a minimum, especially for essential entities such as comments. It’s handy to see from just looking at your controller what data you’re providing. Sure, small queries in a helper is fine, i.e count rows, getting user’s real name etc.
Don’t burry things away to quickly, you may know where they are now and what they’re doing, but 6 months after your site has gone live are you still going to remember so readily?

Loading in the controller and providing it to the views is fine, that’s what I do. Using the stored user_id is fine yes. Remember to ensure that the requested data actually applies to the logged in user though, and not a different one.

Definitely use a partial for that, helpers are intended for providing information, not HTML.

for example:

in the controller:

@user = User.find(params[:id]) # find sanitizes the id for you

if user_logged_in?(@user)

@profile = UserProfile.find(@user)


in the view:

<% if user_logged_in? %>
<%= render :partial => ‘user/profile’ %>

<% end %>

in the partial:

<%= get_friend_count(@user) %>

You could put the friend count query in the controller, but as your actions get more complex and have a wider range of rendering possibilities, you may find you don’t always little things such as this, so it’s nice to put them in a helper. But make sure you don’t duplicate your queries when doing this!

DISCLAIMER: I’m fairly new to Rails myself, don’t please don’t take everything I’ve said as fact!