4

I have an STI relationship where a conversation is composed of both messages and images.

Now when I go to render them i use:

<%= render conversation %>

which works perfect. It finds the given template for the given object and renders it.

Now for my mobile site I want to use the same thing only now it should find say:

/mobile/message/_message.html.erb

instead of

/message/_message.html.erb

So in my controller i said:

if mobile?
  prepend_view_path "mobile"
end

Which does get called, and it "prepends my view path" which i can see is working when i do:

raise view_paths.inspect

However now when i do my

<%= render conversation %>

It is still looking in the default location i.e. /views/ for the partial

Mike Silvis
  • 1,299
  • 2
  • 17
  • 30

1 Answers1

-1

Well, this should work, but it is distressingly inelegant:

<% conversation.each do |c| %>
  <% c_class = c.class.to_s.downcase.underscore %>
  <%= render :partial => "mobile/#{c_class}/#{c_class}", :object => c %>
<% end %>
MrTheWalrus
  • 9,670
  • 2
  • 42
  • 66
  • yes but i can't do this because of STI. Doing it that way would break the rendering because now when it goes to render the image object it would try to do it in the message partial – Mike Silvis Apr 02 '13 at 20:32
  • Ah. I see. I suppose you could derive the partial path using the conversation class (see edit). It does feel like something for which there is a better way. – MrTheWalrus Apr 02 '13 at 21:05
  • this still wouldn't work as expected. conversation is an array. Also with your syntax you need to do: <%= render partial: "mobile/conversation_class", collection: conversation %> – Mike Silvis Apr 02 '13 at 21:11