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 5941329
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:05:40+00:00 2026-05-22T16:05:40+00:00

I have a view that is accessing attibutes from a model .<%= @checklist.alt_escape_indicated %>

  • 0

I have a view that is accessing attibutes from a model

.<%= @checklist.alt_escape_indicated %>

.<%= @checklist.sign_condition %>

Some of these are going to be booleans that I wanted displayed as ‘Yes” or “No”. I’ve written some code in my model class to do this:

def getter_decorator(attr)
  var = read_attribute(attr)
  if !!var == var
    boolean_as_string(var)
  else
    var
  end
end

def boolean_as_string(bool_type)
    if bool_type
      "Yes"
    else
      "No"
    end
end

So I can just do:
.<%= @checklist.boolean_as_string(@checklist.sign_condition) %>

for attributes I know are boolean or getter_decorator on everything. My question is. Is there a way I can decorate all of my getters so this function is called when I do
@checklist.sign_condition

  • 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-22T16:05:41+00:00Added an answer on May 22, 2026 at 4:05 pm

    I’d recommend making this a helper method since it’s solely for presentation. That’ll also make it easier to localize it in the future when your site takes off internationally…

    def yn(val)
      val ? "Yes" : "No"
      # localized: I18n.t (val ? "Yes" : "No")
    end
    

    And then use it in your view:

    <%= yn @checklist.sign_condition %>
    

    However, if you REALLY wanted bools to automatically show up as Yes/No, you could do something like:

    class TrueClass
      def to_s
        self ? "Yes" : "No"
      end
    end
    
    puts true #-> Yes
    

    I wouldn’t recommend that however 😉

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a view that I want to add some custom drawing to. I
I have a view that takes data from my site and then makes it
I have a view that contains two NSTextFieldCell s. The size at which these
I have a strongly typed View that accepts a Customer model, this customer model
I have a view that has a list of jobs in it, with data
I have a View that can vary significantly, depending on the 'mode' a particular
I have a view that is joining two tables and ordering by the first
I have a view that is loaded in the MainWindow.xib. It is just a
I have a view that I want to be converted into JSON. What is
I have a view that will be displaying downloaded images and text. I'd like

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.