I am new to rails and trying to do a little refactoring (putting a partial renderer that lists titles in app/views/shared ) The renderer shows the dates along with the title
Matt's answer is correct for your exact question and I might be way off-mark with understanding your situation but...
I'd pass the entire user object into the partial via the locals hash.
render(
:partial => "shared/titles",
:object => @titles,
:locals => { :user => @user }
)
Then within the partial call a helper method to return the correct date for each title, something like:
<%= title_date_for_user(title, user) %>
Pass the user and each title object to the helper method.
def title_date_for_user(title, user)
case user.date_i_like_to_see
when "created_on"
title_date = title.created_on
when "updated_on"
title_date = title.updated_on
end
return title_date.to_s(:short)
end
The date_i_like_to_see method resides in the User model and returns a string (created_on or updated_on) based on some logic particular to the given user.
This approach tucks away most of the logic and keeps your view nice and clean. Plus it makes it simple to add further features specific to a given user later.