Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 930955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T20:25:22+00:00 2026-05-15T20:25:22+00:00

I have a Note model, which can contain have either an image link attachment

  • 0

I have a Note model, which can contain have either an image link attachment (linktype = “image” or some text (linktype = “text). When I display the notes, the method of display changes depending on the linktype. An example is:

<% @notes.each do |q| %>
    <h2 class="title"><%= q.name %></h2>
    <% if q.linktype == "image"%>
        <img src="<%= q.link %>" />
    <% elsif q.linktype == "text"%>
        <%= q.text %>
    <% end %>
<% emd %>

I have to display the notes in a few different views in my site, so rather than have to repeat the viewing code multiple times, I want to have it in one place and refer to it from different views.

Should I do this in the application helper? If so, do I put the display code, like the code above, directly into the helper, or is there a better way? Thanks for reading.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T20:25:22+00:00Added an answer on May 15, 2026 at 8:25 pm

    For repeating view code that has nothing to do with some entity (is not, say, users/show.html.erb) make a widgets folder and write your partial there. I put in my widgets nav-bars and such.

    /app/views/widgets/widget1.html.erb
    /app/views/widgets/widget2.html.erb
    ...
    
    # some_view.html.erb
    <%= render :partial => 'widgets/widget1' %>
    

    In an abstract way, I make the difference between helpers and this kind of partials as so:

    • helpers are for view-related logic (iterate in a special way etc)
    • view widgets are data image, they just match holes with data
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Note model, which can contain have either an image link attachment
I have a model class like this: class Note(models.Model): author = models.ForeignKey(User, related_name='notes') content
Note: Full code can be found at http://github.com/basicxman/andrewhorsman.net I have a Tag model and
I have got an Entity model which contains a collection of Message objects which
I have a complex view model which contains a collection of other objects which
I have a Review model which allows for a '1-10' rating system on products.
Hi I have a view which displays Invoices and InvoiceLines . @model VectorCheck.ViewModels.InvoiceViewModel @{
I have the following classes: public class Note { public string Text { get;
I have an application that manages documents called Notes. Like a blog, Notes can
I have a static method 'findAll' on a model which basically gets all rows

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.