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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T21:45:41+00:00 2026-06-05T21:45:41+00:00

In my view, let’s say I have something like this: <%= f.text_field :name_first %>

  • 0

In my view, let’s say I have something like this:

<%= f.text_field :name_first %>

and another time this:

<%= f.text_field :name_last %>

Instead of hard-coding the field names, I want to dynamically generate them using a view helper method.

def category_name
    @contact_info.category.name
end

def return_field_name
  category_lower = category_name.downcase
  ":name"+category_lower  
end

So now my view should have something like this:

 <%= f.text_field return_field_name %>
  • 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-05T21:45:43+00:00Added an answer on June 5, 2026 at 9:45 pm

    Write:

    def return_field_name
      category_lower = category_name.downcase
      "name#{category_lower}".to_sym
      # but I'm sure that without #to_sym it should work as well
    end
    

    But if it will help you you should write only pure methods. IMHO it’s very good practice.

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

Sidebar

Related Questions

Let's say I have some classes like this: abstract class View(val writer: XMLStreamWriter) {
Let's say I have a QTableView with a corresponding model. This view shows numbers
I have a view (let's say View B) positioned on top of another view
So let's say I have a view that access a date: <%= Html.TextBoxFor(model =>
Let's say I have 5 revisions of a README file. How do I view
I have a tableview and a normal view (let's say view 2) inside a
I have a regular app with a bunch of view controllers - let's say
This is a weird one. Probably painfully obvious. :D I have a View (let's
In my project, there are two view controllers - let's say firstViewController and secondViewController.
Let's say before a user is allowed to view the creation page of a

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.