I have a Note model that can contain either a link to an image (linktype = "image" or some text (linktype = "text). When I show notes, the display method changes depending on the type of linktype. Example:
<% @notes.each do |q| %>
<h2 class="title"><%= q.name %></h2>
<% if q.linktype == "other"%>
<script type="text/javascript">some javascript</script>
<% elsif q.linktype == "text"%>
<%= q.text %>
<% elsif q.linktype == "image"%>
<img src="<%= q.link %>" />
<% end %>
<% end %>
I need to display notes in several different views on my site, so instead of repeating the view code several times, I want to have it in one place and refer to it from different points of view.
My initial thought was to put the display code in the helper, something like this:
<% @notes.each do |q| %>
note_display(q.linktype, q.link)
<% end %>
javascript ( 4 ). , javascript? , ? .