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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T02:44:05+00:00 2026-06-04T02:44:05+00:00

the model like this: create_table user_accounts, :force => true do |t| t.string code t.string

  • 0

the model like this:

create_table "user_accounts", :force => true do |t|
  t.string   "code"
  t.string   "user_name"
  t.integer  "user_type",  :default => 1
end

the controller’s code like this:

def index
  @user_accounts = UserAccount.all

  respond_to do |format|
    format.html # index.html.erb
    format.json { render :json => @user_accounts }
    format.xml { render :xml => @user_accounts }
  end
end

The View’s code like this:

<table>
  <tr>
    <th><%= t :code %></th>
    <th><%= t :user_name %></th>
    <th><%= t :user_type %></th>
    <th></th>
    <th></th>
    <th></th>
  </tr>

<% @user_accounts.each do |user_account| %>
  <tr class="<%= cycle('list_line_odd', 'list_line_even') %>">
    <td><%= user_account.code %></td>
    <td><%= user_account.user_name %></td>
    <td><%= user_account.user_type %></td>
    <td><%= link_to 'Show', user_account %></td>
    <td><%= link_to 'Edit', edit_user_account_path(user_account) %></td>
    <td><%= link_to 'Destroy', user_account, :confirm => 'Are you sure?', :method => :delete %></td>
  </tr>
<% end %>
</table>

Everything works fine. but there is a flaw that the ‘user_type’ displayed as a number. but i hope it can display as string like ‘normal user’ or ‘system admin’.

The most important thing that I DON’T want to add any logic in the view(index.html.erb).

So what i need is to change the user_type’s value at the controller or wherever.

there must be some elegant ways to do it. But i don’t know.Hope you guys can give me some suggestion. Thanks!

  • 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-06-04T02:44:07+00:00Added an answer on June 4, 2026 at 2:44 am

    You can add to you model UserAccount some function like this

    def user_type_string
        case self.user_type
        when 1
           return "Super user"
        when 2
           return "Something else"
        else
        end
    end
    

    And this method you can use in the view

    <td><%= user_account.user_type_string %></td>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I got a model like this: matrices ( matricesID integer; x integer; y integer;
Say I've got a domain model created from C# classes like this: public class
I'd like to do something like this: class Task(models.Model): ... created_by = models.ForeignKey( User,
I've got a model like this def upload_location(instance, filename): return 'validate/%s/builds/%s' % (get_current_user(), filename)
I have a simple model like this one: class Artist(models.Model): surname = models.CharField(max_length=200) name
I have entity model like this (using EclipseLink and JPA 2.0): @Entity class A
I have model like this: scope :search_posts, lambda { |query| mega_posts.where( title LIKE ?
I am trying to design a tagging system with a model like this: Tag:
I'm using MVC3 and I have a model like this: public class Foo {
I'm using Doctrine ODM with MongoDB. I have a product model like this: namespace

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.