I have a note model that can contain an image link (linktype = "image" or some text (link) Type = "text). When I display the notes, the method of change displayed on the basis of the link type. For example:
<% = q.name%> <% if q.linktype == "image"% & Gt; & lt; img src = "& lt;% = q .Link%> & gt; "/> <% Elsif q.linktype ==" lesson "%> gt; <% = q.text%> <% end%> <% AMD% & amp; Gt; I have to display notes in some different scenes of my site, so rather than replacing the code several times, I want to place it in one place and separate it I want to refer to this.
Should I make this application helpful? If so, should I put the display code directly in the Assistant as above code, or better Thanks for reading. / P>
For repeating code in which anything with some entity (Do not say, say, In a simple way, I use helpers and such Doing this as a difference in partialities: users / show.html.erb ) Create a widgets folder and partially write there. I have put my widgets in the navbar and so on.
/app/views/widgets/widget1.html.erb/app/views/widgets/widget2.html.erb ... # some_view .html.erb & lt;% = Render: Partial = & gt; ; 'Widgets / Widget1'% & gt;
Comments
Post a Comment