user2572790
user2572790

Reputation: 476

Faster Rails single partial render

I need to avoid an often repeat of the same code block into template. Example:

%a{href:item_path(item.web_title,@relative_link_options)}
  =item.show_field_locale('title')
  -unless item.get_image_path('has_image',"item_#{item.id}.png").blank?
    =image_tag(item.get_image_path('has_image',"item_#{item.id}.png"))

So, I describe many items, NOT from collection @items. That are has-one relations or small has-many relations. I have a lot of such pages, so too many different content for caching.

To display every item I need to repeat an above code block. Also I could use partial _item.html.haml and use it via render partial: 'item' But it slows an application (time to prepare Views in ms). How could I avoid it?

Upvotes: 0

Views: 52

Answers (1)

Igor Kasyanchuk
Igor Kasyanchuk

Reputation: 774

For example, I'm solving such problem with https://github.com/igorkasyanchuk/embed_view

but it requires to have ERB views

Upvotes: 1

Related Questions