How do you deal with naming conventions for rails partials?

Posted by DJTripleThreat on Stack Overflow See other posts from Stack Overflow or by DJTripleThreat
Published on 2010-05-07T11:22:38Z Indexed on 2010/05/07 11:38 UTC
Read the original article Hit count: 279

For example, I might have an partial something like:

<div>
  <%= f.label :some_field %><br/>
  <%= f.text_field :some_field %>
</div>

which works for edit AND new actions. I also will have one like:

<div>
  <%=h some_field %>
</div>

for the show action. So you would think that all your partials go under one directory like shared or something. The problem that I see with this is that both of these would cause a conflict since they are essentially the same partial but for different actions so what I do is:

<!-- for edit and new actions -->
<%= render "shared_edit/some_partial" ... %>

<!-- for show action -->
<%= render "shared_show/some_partial" ... %>

How do you handle this? Is a good idea or even possible to maybe combine all of these actions into one partial and render different parts by determining what the current action is?

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about partial